在处理UITableView表格时,我们希望在View底部添加按钮。

用户拖动UITableView时按钮能跟随移动。

如题,实现如下界面:

- (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;
}
}

原文章地址:http://www.2cto.com/kf/201506/407035.html

UITabelViewFootView(转)的更多相关文章

随机推荐

  1. Java下String和List<String>的互相转换

    // List转换为String数组 List<String> list = new ArrayList<String>(); list.add("a1") ...

  2. Linux下交叉编译gdb和gdbserver

    平台:tq2440 GCC:  gcc version 4.3.3 (Sourcery G++ Lite 2009q1-176) 这里过程中参考了下面两篇博文: http://blog.csdn.ne ...

  3. linux tail 命令详解!Linux 文件内容查看工具介绍

    转:http://blog.csdn.net/carzyer/article/details/4759593 1.cat 显示文件连接文件内容的工具: cat 是一个文本文件查看和连接工具.查看一个文 ...

  4. 【java】java中直接根据Date 获取明天的时间

    展示代码: @Test public void dateTest(){ Date now = new Date(); System.out.println(now); // java.util.Dat ...

  5. ASP.NET MVC DropdownList的使用

    1:直接使用HTML代码写 <select name="year"> <option value="2011">2010</opt ...

  6. iOS:创建静态库及其使用

    本篇来自转载,原创链接为:http://my.oschina.net/leejan97/blog/284193 摘要: 静态库文件可以有效的将功能封装和细节隐藏  ios 静态库 static lib ...

  7. 关于group by后为每个分组编号

  8. Python 获取图片文件大小并转换为base64编码

    import os import base64 fileSize = os.path.getsize(文件路径) with open(文件路径, 'rb') as f: data = base64.b ...

  9. centos7 minimal connect: Network is unreachable(转)

    新装的centos7,果然是很崭新啊. 装好之后打算看一下局域网的地址,然后就ip addr(centos 7 已经去掉了ifconfig这个命令).并没有显示局域网的ip地址. 然后我尝试ping ...

  10. Microsoft.VisualC 命名空间包含支持用 c + + 语言的代码生成和编译的类。 混合编程中使用COM接口指针

    Microsoft.VisualC 命名空间包含支持用 c + + 语言的代码生成和编译的类. Microsoft.VisualC.StlClr Unmanaged Code 和 Managed Co ...