• iOS UITableView的Section Footer加入button


    郝萌主倾心贡献,尊重作者的劳动成果。请勿转载。

    假设文章对您有所帮助,欢迎给作者捐赠。支持郝萌主,捐赠数额任意。重在心意^_^ 

    我要捐赠: 点击捐赠

    Cocos2d-X源代码下载:点我传送


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

    郝萌主倾心贡献。尊重作者的劳动成果,请勿转载。

    假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主。捐赠数额任意,重在心意^_^ 

    我要捐赠: 点击捐赠

    Cocos2d-X源代码下载:点我传送

  • 相关阅读:
    RMI几种公布和引用服务的方式
    mysql 多日志表结果集合拼接存储过程
    USRP通信的结构体和常量(上位机、下位机共用)
    Flash Builder4破解步骤
    leetcode 217 Contains Duplicate 数组中是否有反复的数字
    关于权限表的基本设计
    Objective-C之成魔之路【7-类、对象和方法】
    vs2008C1902程序数据库管理不匹配
    配置hadoop集群一
    BZOJ 2338 HNOI2011 数矩形 计算几何
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5063687.html
Copyright © 2020-2023  润新知