UITabelViewFootView(转)

在处理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

转载于:https://www.cnblogs.com/xiaoxiaoyublogs/p/5156637.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值