LCStretchableHeaderViewController
功能介绍
- 提供一个UIViewController的子类LCStretchableHeaderViewController,支持设置stretchableHeader,实现下拉的时候,header放大,类似于qq空间的效果
- 支持向上滑动,导航栏的颜色渐变效果
- 提供代理,当navigationBar在Transparent和Normal状态切换的时候,设置navigationBar的子视图的样式
如何使用
- pod "LCStretchableHeaderViewController"
- 使用代码示例:
//配置
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupUI];
}
- (void)setupUI
{
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"DEMO";
self.navBarNormalColor = [UIColor greenColor];
self.ignoredTopOffset = 200;//这个高度一般设置的跟headerView的一样
//add subview
self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
self.headerView.backgroundColor = [UIColor redColor];
//set frame
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
tableView.rowHeight = 88;
tableView.delegate = self;
tableView.dataSource = self;
self.containerView = tableView;
}
//代理:根据状态的不同修改item的颜色
- (void)lc_navgigationBarStateChanged:(LCNavigationBarState)barState
{
NSLog(@"state = %ld", barState);
if (barState == LCNavigationBarStateTransparent)
{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Transparent" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}else
{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Normal" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
}
}
效果截图
demo.gifgit:https://github.com/jayhe/LCStretchableHeaderViewController
网友评论