gpt4 book ai didi

iphone - 如何设置 UITableView 标题 View 的宽度?

转载 作者:行者123 更新时间:2023-12-01 18:01:07 26 4
gpt4 key购买 nike

有没有办法将 UITableView 部分标题 View 的宽度设置为小于 UITableView 的全宽?现在无论我设置 tableView:viewForHeaderInSection: 返回的 View 有多宽,标题 View 都会拉伸(stretch)到 UITableView 的宽度。

这是我的代码:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *label = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 50, 50)];
label.backgroundColor = [UIColor yellowColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
return label;
}

最佳答案

试试这个。,如果我理解你的问题,这肯定对你有用

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 60)];
headerView.backgroundColor = [UIColor clearColor];

UIView *label = [[UIView alloc] initWithFrame: CGRectMake(0,0, 50, 50)];
label.backgroundColor = [UIColor yellowColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

[headerView addSubview:label];
return headerView;
}

关于iphone - 如何设置 UITableView 标题 View 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9745180/

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