首页 > 其他 > 详细

UI tableView 的头视图 & "小广告"

时间:2015-08-29 11:11:47      阅读:163      评论:0      收藏:0      [点我收藏+]
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. 可以刷新数据.

版权声明:本文为博主原创文章,未经博主允许不得转载。

UI tableView 的头视图 & "小广告"

原文:http://blog.csdn.net/gao_zi/article/details/48085237

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!