Comments (3)
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
}
}
from stretchheader.
Thank you a lot !!!
from stretchheader.
I try everything , but still I can't display label above navigation bar after it become with solid color
from stretchheader.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stretchheader.