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

UITableView添加footerView按钮

2016-02-12 23:09 351 查看

UITableView添加自定义的footerView按钮

注:不需要设置footer的尺寸

// 设置footerView
// 注意:不需要设置footer的尺寸
MJTgFooterView *footer = [MJTgFooterView footerView];
footer.controller = self;
self.tableView.tableFooterView = footer;


UITableView添加代码创建的footerView按钮

// 设置tableview尾部显示的控件(tableFooterView的宽度永远是tableView的宽度)
// tableFooterView只需要设置高度
UIButton *footerBtn = [UIButton buttonWithType:UIButtonTypeSystem];
footerBtn.frame = CGRectMake(0, 0, 0, 35);
footerBtn.backgroundColor = [UIColor orangeColor];
[footerBtn setTitle:@"加载更多团购" forState:UIControlStateNormal];

// 创建nib对象
// UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:[NSBundle mainBundle]];

// 创建nib对象(也可以传入nil - 解释:凡是参数需要传入[NSBundle mainBundle]的都可以使用nil代替,因为默认的就是mainBundle)
UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil];

// 因为在tableFooterView中的控件是不可调位置和宽度的,所以要新建个UIView的xib文件来描述底部控件
// 加载xib/nib文件
UIView *footerView = [[nib instantiateWithOwner:nil options:nil] lastObject];
self.tableView.tableFooterView = footerView;


以上代码的注意点:

1)footerBtn.frame = CGRectMake(0, 0, 0, 35);

//前三个属性不需要设置,只需要设置一个高度,宽度不需要去设置,宽度就是UIViewTable的宽度

2)使用另一种方法来获取xib文件,之前使用[NSBundle mainBundle]来获取的

UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:[NSBundle mainBundle]];

// 之前使用[NSBundle mainBundle]来获取的
NSBundle *bundle = [NSBundle mainBundle];
NSArray *objs = [bundle loadNibNamed:@"MJTgFooterView" owner:nil options:nil];
UIView *appView = [objs lastObject];


注:也可以传入nil - 解释:凡是参数需要传入[NSBundle mainBundle]的都可以使用nil代替,因为默认的就是mainBundle

UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil];


3)因为在tableFooterView中的控件是不可调位置和宽度的,所以要新建个UIView的xib文件来描述底部控件

UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil];
UIView *footerView = [[nib instantiateWithOwner:nil options:nil] lastObject];

// 之前使用[NSBundle mainBundle]来获取的
NSBundle *bundle = [NSBundle mainBundle];
NSArray *objs = [bundle loadNibNamed:@"MJTgFooterView" owner:nil options:nil];
UIView *appView = [objs lastObject];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: