avf*_*avf 5 iphone header footer uitableview
我想在UITableView的页脚中显示一个UIButton(对于标题应该完全相同).
这段代码在我的TableViewController的viewDidLoad中:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
NSLog(@"%f", footerShareButton.frame.size.width);
[self.tableView setTableFooterView:footerShareButton];
NSLog(@"%f", footerShareButton.frame.size.width);
NSLog(@"%f", self.tableView.tableFooterView.frame.size.width);
Run Code Online (Sandbox Code Playgroud)
但是,此代码不起作用.Button的宽度太大,它是320.(虽然高度正确.)第一个NSLog输出70,第二个和第三个输出320.所以看起来setTableFooterView方法奇怪地调整了按钮的大小.
我已经将UIButton放在另一个UIView中,然后将其设置为表格页脚,从而解决了这个问题:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 70, 50)];
[aView addSubview:footerShareButton];
[self.tableView setTableFooterView:aView];
[aView release];
Run Code Online (Sandbox Code Playgroud)
这样做,按钮具有正确的宽度.
但是,我不明白为什么第一个代码示例不起作用.谁能解释一下?
Mic*_*ler 19
无论您设置为视图的宽度是否作为UITableView页脚/标题添加- 其宽度始终与表格的宽度相同.
因此,在您的情况下,您添加的视图已调整为大小CGRectMake(0, 0, 320, 50),但按钮仍保留正确的框架.按钮的框架是根据视图...
编辑:
页脚/标题框架中唯一保留的参数是高度.
请注意,如果在将页眉/页脚视图添加到表格后更改页眉/页脚视图的高度,它将不会进行任何更改.您应该在将其添加到表格之前设置高度...
| 归档时间: |
|
| 查看次数: |
9496 次 |
| 最近记录: |