iOS UITableView的Section Footer加入button
2015-12-21 15:55
369 查看
在处理UITableView表格时,我们希望在View底部加入button。
用户拖动UITableView时button能尾随移动。
如题。实现例如以下界面:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (section >= kSetSetting) { return 80; } else{ return 2; } } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if (section >= kSetSetting) { UIView *footerView = [[UIView alloc] init]; footerView.userInteractionEnabled = YES; footerView.backgroundColor = [UIColor clearColor]; UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem]; [loginButton.layer setMasksToBounds:YES]; [loginButton.layer setCornerRadius:5.0]; [loginButton setBackgroundColor:[UIColor brownColor]]; [loginButton setTitle:@"登陆" forState:UIControlStateNormal]; [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [loginButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; [loginButton setTranslatesAutoresizingMaskIntoConstraints:NO]; [loginButton addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside]; //[footerView addSubview:btnExit]; [footerView addSubview:loginButton]; UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeSystem]; [registerButton.layer setMasksToBounds:YES]; [registerButton.layer setCornerRadius:5.0]; [registerButton setBackgroundColor:[UIColor brownColor]]; [registerButton setTitle:@"注冊" forState:UIControlStateNormal]; [registerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [registerButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; [registerButton setTranslatesAutoresizingMaskIntoConstraints:NO]; [registerButton addTarget:self action:@selector(registerBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [footerView addSubview:registerButton]; NSDictionary *constraintsView = NSDictionaryOfVariableBindings(loginButton,registerButton); [footerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-15-[loginButton]-15-|" options:0 metrics:nil views:constraintsView ]]; [footerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-20-[loginButton]" options:0 metrics:nil views:constraintsView ]]; [footerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-15-[registerButton(==loginButton)]-15-|" options:0 metrics:nil views:constraintsView ]]; [footerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[loginButton]-30-[registerButton(==loginButton)]-20-|" options:0 metrics:nil views:constraintsView]]; return footerView; } else { return nil; } }
相关文章推荐
- [easyui]实际应用中遇到的问题
- ueditor-------百度编辑器,跨目录上传图片等
- 使用UITableview实现横向滚动
- String、StringBuffer、StringBuilder区别
- Troubleshooting "Global Enqueue Services Deadlock detected" (Doc ID 1443482.1)
- iOS开发之如何在NSURLRequest中设置自定义header请求头
- UITableView 刷新头部时,头部每次都变为开始的状态,无法记录当前的状态
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 【PHP】PHP include()和require()方法的区别
- ios图片缩放,根据UIImageView Frame的尺寸,自动调整UIImage缩放,保证图片显示不变形
- UIMenuContnroller的使用
- Android BlueDroid(一):BlueDroid概述
- Hello : break continue return
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- Ant_build.xml解释
- iOS开发日记53-CALayer和UIView
- 报错:finished with non-zero exit value 2
- android 蓝牙 bluetooth OPP文件传输