在一组UITableViewController
中的UITableView
,想调整它的水平尺寸。已经试了好几种方法,但是都不太理想。
第一种方法:重写了-[UITableView setFrame:]
但是标题部分没移动,而且两边还出现了黑色的空。(tableVIew已经是最底层了)
第二种方法:重写了-[UITableViewCell setFrame:]
,但是标题部分还是没移动,(这个必须移动)
第三种方法:调用UITableViewController
中的- [self.view setFrame:]
,没实现。不知道该怎么办了,请大家帮忙。
如果你调用- [UITableViewController viewDidAppear:]
中的- [UITableView setFrame:]
,这样会有用:
- (void)viewDidAppear:(BOOL)animated
{
[self.tableView setFrame:CGRectMake(x, y, w, h)];
}
为了防止tableview两边出现黑条,设置背景颜色为白色:
[[[UIApplication sharedApplication] keyWindow] setBackgroundColor:[UIColor whiteColor]];
要调整标题的尺寸,我的代码如下:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGFloat headerHeight = 40;
UIView *headerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, headerHeight)];
UILabel *cellLabel = [[UILabel alloc] initWithFrame: headerView.frame];
[cellLabel setText: @"My Text"];
[cellLabel setBackgroundColor: [UIColor clearColor]];
[headerView addSubview: cellLabel];
return headerView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 40;
}
这段代码是取代这个方法:
`- (NSString *) tableView:(UITableView *)tableView `titleForHeaderInSection:`(NSInteger)section`