-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to display label after scrolling ? #3
Comments
I try everything , but still I can't display label above navigation bar after it become with solid color |
I think putting a label on the variable "navigationView". import UIKit
class Demo1Controller: UIViewController, UITableViewDataSource, UITableViewDelegate {
var header : StretchHeader!
var tableView : UITableView!
var navigationView = UIView()
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.navigationController?.interactivePopGestureRecognizer?.delegate = nil;
}
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: view.bounds, style: .plain)
tableView.dataSource = self
tableView.delegate = self
view.addSubview(tableView)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "TableViewCell")
setupHeaderView()
// NavigationHeader
let navibarHeight : CGFloat = navigationController!.navigationBar.bounds.height
let statusbarHeight : CGFloat = UIApplication.shared.statusBarFrame.size.height
navigationView = UIView()
navigationView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: navibarHeight + statusbarHeight)
navigationView.backgroundColor = UIColor(red: 121/255.0, green: 193/255.0, blue: 203/255.0, alpha: 1.0)
navigationView.alpha = 0.0
view.addSubview(navigationView)
// I will add this (navigationbar titlelabel)
let label = UILabel()
label.frame = CGRect(x: 0, y: statusbarHeight, width: view.frame.size.width, height: navibarHeight)
label.text = "navigation title";
label.textAlignment = .center
label.textColor = UIColor.white
navigationView.addSubview(label)
let button = UIButton(type: .custom)
button.frame = CGRect(x: 10, y: 20, width: 44, height: 44)
button.setImage(UIImage(named: "navi_back_btn")?.withRenderingMode(.alwaysTemplate), for: UIControlState())
button.tintColor = UIColor.white
button.addTarget(self, action: #selector(Demo1Controller.leftButtonAction), for: .touchUpInside)
view.addSubview(button)
}
func setupHeaderView() {
let options = StretchHeaderOptions()
options.position = .fullScreenTop
header = StretchHeader()
header.stretchHeaderSize(headerSize: CGSize(width: view.frame.size.width, height: 220),
imageSize: CGSize(width: view.frame.size.width, height: 220),
controller: self,
options: options)
header.imageView.image = UIImage(named: "photo_sample_05")
// custom
let label = UILabel()
label.frame = CGRect(x: 10, y: header.frame.size.height - 40, width: header.frame.size.width - 20, height: 40)
label.textColor = UIColor.white
label.text = "StrechHeader Demo"
label.font = UIFont.boldSystemFont(ofSize: 16)
header.addSubview(label)
tableView.tableHeaderView = header
}
// MARK: - Selector
func leftButtonAction() {
self.navigationController?.popViewController(animated: true)
}
// MARK: - ScrollView Delegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
header.updateScrollViewOffset(scrollView)
// NavigationHeader alpha update
let offset : CGFloat = scrollView.contentOffset.y
if (offset > 50) {
let alpha : CGFloat = min(CGFloat(1), CGFloat(1) - (CGFloat(50) + (navigationView.frame.height) - offset) / (navigationView.frame.height))
navigationView.alpha = CGFloat(alpha)
} else {
navigationView.alpha = 0.0;
}
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 20
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath)
cell.textLabel?.text = "index -- \((indexPath as NSIndexPath).row)"
return cell
}
} |
Thank you a lot !!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ,
I'm trying to display label when the header become small (after scrolling)
how can I do that ?
The text was updated successfully, but these errors were encountered: