【发布时间】:2011-09-21 10:48:30
【问题描述】:
编辑:
在搞砸了几天之后,我遇到的真正问题如下:
1. UITableView 是否占据了整个视图?
2. 如果是这样,它如何将单元格的边界设置为看起来只占用部分视图。
3. 我如何获得细胞的边界——或者更准确地说,我如何知道细胞占据的可见区域的边界。 self.tableView.bounds.size.width 没有帮助,因为它返回视图的宽度。
谢谢。
留下之前的信息,以防它有助于使我的问题更清楚。
这可能吗? 我已经阅读了苹果文档并在这里和其他地方浏览了论坛,但无法找到并回答这个问题。 不管你做什么,UITableVIew 中的页脚是否真的占据了整个视图?没有表格宽度的概念吗?
例子:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
[footerView setBackgroundColor:[UIColor redColor]];
return footerView;
}
此代码将创建一条从一条边到另一条边的红线。无论你给它什么边界,这条线都会占据整个视图。这样做的问题是,如果您想在该页脚中将标签居中,如果您支持方向更改,您将无法知道中心在哪里。 例如,在 iPad 应用程序中,我尝试执行以下操作:
if ([footerText length] > 0) {
UIView *customView = [[[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 0, 0.0)] autorelease];
[customView setBackgroundColor:[UIColor grayColor]];
UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
footerLabel.numberOfLines = 2;
footerLabel.adjustsFontSizeToFitWidth = NO;
[footerLabel setTextAlignment:UITextAlignmentCenter];
[footerLabel setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
[footerLabel setOpaque:NO];
[footerLabel setTextColor:[UIColor whiteColor]];
[footerLabel setShadowColor:[UIColor lightGrayColor]];
[footerLabel setFont:[UIFont boldSystemFontOfSize:14]];
[footerLabel setFrame:CGRectMake(customView.center.x/0.3, 0.0, 600, 40.0)];
[footerLabel setText:footerText];
[customView addSubview:footerLabel];
[footerLabel release];
NSLog(@"customView width = %f", customView.frame.size.width);
NSLog(@"tableview width = %f", self.tableView.frame.size.width);
NSLog(@"tableview center = %f", self.tableView.center.x);
return customView;
} else {
return nil;
}
纵向的表格中心应为 384(位于详细视图/右侧),横向为 351.5。但是当我使用 setCenter 或尝试根据该中心调整左边缘时,它不会居中。
最后一个问题:当页脚似乎没有表格边界的概念时,如何在页脚中将自定义视图居中并支持方向?我一定在文档中遗漏了一些东西,因为这必须是其他人解决的问题,但我找不到。 感谢您的宝贵时间。
【问题讨论】:
标签: ios uitableview orientation tableview footer