UI tableView 的头视图 & "小广告"
2015-08-29 10:15
453 查看
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain]; [self.view addSubview:self.tableView]; [_tableView release]; self.tableView.dataSource = self; self.tableView.delegate = self; // 设置cell行高 self.tableView.rowHeight = 100; self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 200)]; self.imageView.image = [UIImage imageNamed:@"5.jpg"]; // 给tableview添加头视图(不动得一张图) // 宽是tableView的宽度 self.tableView.tableHeaderView = self.imageView;
这样设置图片当你在下拉时,不会有任何改变.
可以试试以下代码的效果!
- (void)viewDidLoad { // 格外小广告 [self.tableView addSubview:self.imageView]; self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0); } #pragma mark tableView 的delegate 已经签订好了scrollView的协议,只要设置好代理人,就可以使用scrollView的协议方法. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ CGFloat y = scrollView.contentOffset.y; if (y < 0) { self.imageView.frame = CGRectMake(0, y, self.view.frame.size.width, -y); } NSLog(@"%g",y); }
当然不要忘了写协议中的方法.
tableView有一个方法reloadData. 可以刷新数据.
相关文章推荐
- Win10正式版怎么删除搜狗输入法中的SogouExe顽固文件?
- UVA 1605 Building for UN
- UI 07 界面传值 之 从后向前 ---- 协议传值
- HDU 5147 Sequence II (线段树求前缀和、后缀和)
- UIView的alpha、hidden和opaque属性之间的关系和区别
- C#基础----string和stringBuilder
- Win10 10525升级Win10 Build 10532失败回滚怎么办?
- POJ 3080 Blue Jeans(水~)
- 单行文本框和多行文本框UiTextfield UiTextView
- POJ 2871 A Simple Question of Chemistry(水~)
- POJ 2785 4 Values whose Sum is 0(hash表)
- 从数据库中提取到ueditor并且重新编辑
- POJ 2664 && HDU 1144 Prerequisites?(水~)
- 【LeetCode-面试算法经典-Java实现】【225-Implement Stack using Queues(用队列实现栈操作)】
- 6、iOS 开发之 UIPickerView
- 4、iOS 开发之 UITableView
- 3、iOS 开发之 UIScrollView UIPageController NSTimer
- iOS部分-UI基础控件 - 01天 入门 第11课 上下左右移动
- 新建Android工程报错:'Building workspace' has encountered a problem...解决办法
- ngui自适应的一点学习