iOS UITableView的Section Footer添加按鈕

來源:互聯網
上載者:User

iOS UITableView的Section Footer添加按鈕

 

 

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

 

郝萌主傾心貢獻,尊重作者的勞動成果,請勿轉載。

如果文章對您有所協助,歡迎給作者捐贈,支援郝萌主,捐贈數額隨意,重在心意^_^

我要捐贈: 點擊捐贈

Cocos2d-X源碼下載:點我傳送

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.