您的位置:首页 > 产品设计 > UI/UE

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. 可以刷新数据.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: