gpt4 book ai didi

ios - UITableView : set the header frame of view in UITableView doesn't work

转载 作者:行者123 更新时间:2023-11-29 10:33:59 24 4
gpt4 key购买 nike

我需要在 UITableView 的第一节标题中添加一个 UIButton

这是我的代码:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section == 0) {

UIButton *createGroupBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, tableView.frame.size.width - 100, 50)];
// other code...
return createGroupBtn;
}
return nil;
}

你看,我已经为页眉的框架添加了约束。 (例如,宽度小于 tableview 的框架的 100。)

以下是我 iPhone 中的结果:

enter image description here

显然,红色按钮的宽度仍然等于 tableview 的宽度。

我是否遗漏了其他一些使框架约束起作用的重要代码?

最佳答案

首先,您没有添加任何约束,您只是设置了框架。节标题始终与表格宽度相同。如果您希望按钮更窄,那么您应该创建一个 UIView,将按钮添加到其中(任意大小),然后将 View 作为节标题返回。

关于ios - UITableView : set the header frame of view in UITableView doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28038818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com