iOS UITableView的Section Footer加入button「建议收藏」

iOS UITableView的Section Footer加入button

大家好,又见面了,我是全栈君。

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

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

我要捐赠: 点击捐赠

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

在处理UITableView表格时,我们希望在View底部加入button。

用户拖动UITableView时button能尾随移动。

如题。实现例如以下界面:

iOS UITableView的Section Footer加入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源代码下载:点我传送

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116599.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ES6 模板字符串方法[通俗易懂]

    ES6 模板字符串方法[通俗易懂]ES5中在JS中写一个模块是这样的:varcontent=’’+’’+title+’’+’’在ES6中可以这样:let这里就直接写不用引号什么的<div>${变量}<div>方便快捷用的是两个烦引号“来包裹模块…

    2022年8月21日
    8
  • 两数之和c语言实现[通俗易懂]

    两数之和c语言实现[通俗易懂]int*twoSum(int*nums,intnumsSize,inttarget,int*returnSize){inti=0,j=0;*returnSize=2;int*a=(int*)malloc(sizeof(int)*2);for(i=0;i<numsSize;i++)…

    2022年6月13日
    31
  • springboot全局字符编码设置(解决乱码问题)

    springboot全局字符编码设置(解决乱码问题)有时候我们会发现这种问题,明明已经设置了字符编码过滤器但是还会有乱码的情况出现,这个问题令我们很是头疼,我之前也遇到过这种情况。那怎么解决呢?springboot编码格式设置有三种方式,不管使用哪种方式,总有一款适合你。1、在application.properties中设置#编码格式spring.http.encoding.force=truespring.http.encod…

    2022年4月27日
    349
  • 前缀、中缀、后缀表达式「建议收藏」

    前缀、中缀、后缀表达式「建议收藏」关键字:概念,前缀表达式,前缀记法,中缀表达式,中缀记法,波兰式,后缀表达式,后缀记法,逆波兰式它们都是对表达式的记法,因此也被称为前缀记法、中缀记法和后缀记法。它们之间的区别在于运算符相对与操作数的位置不同:前缀表达式的运算符位于与其相关的操作数之前

    2022年6月16日
    37
  • js字符串转数组(js如何将中文字符串转为数组)

    split()方法varcolors=”red,blue,yellow”;//字符串varcolorsA=colors.split(“,”);//以,进行分割字符串,返回数组console.log(colorsA);

    2022年4月14日
    87
  • 焦点科技怎么老是招人_选错对焦点,错失好照片,你了解相机的对焦吗?

    焦点科技怎么老是招人_选错对焦点,错失好照片,你了解相机的对焦吗?对焦一直是衡量相机的性能的重要参数,在很长的一段时间里,我们因为相机的对焦系统不够强大,而习惯的单点手动设置对焦。而近几年微单相机的对焦快速发展,眼部自动对焦已经比较成熟,而我们的习惯也应该发生改变……选错对焦点,错失好照片多好的构图,妹子笑的多甜,然而就是因为焦点没有对准,成功的变成一张废片。很多人和我抱怨过,什么镜头跑焦,机身跑焦,可是你们有没有从自身找过原因,当真找到正确的焦点,准确合…

    2022年6月6日
    330

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号