UITableView 的 tableViewHeader 属性是一个 UIView 所以我想我可以向它添加多个子视图。但是,当我为分段控件添加代码时,UILabel 在它不绘制前几行。矩形不应相互重叠。
我究竟做错了什么?
- (void)viewDidLoad {
[super viewDidLoad];
CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, 50.0);
UIView *trialHeaderView = [[UIView alloc] initWithFrame:newFrame];
trialHeaderView.backgroundColor = [UIColor clearColor];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(15.0, 10.0, 75.0, 25.0)] autorelease];
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = @"TaDa!";
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
[trialHeaderView addSubview:label];
[label release];
CGRect frame = CGRectMake(80, 10, 100, 35);
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithFrame:frame];
[seg insertSegmentWithTitle:@"Start" atIndex:0 animated:NO];
[seg insertSegmentWithTitle:@"End" atIndex:1 animated:NO];
[trialHeaderView addSubview:seg];
[seg release];
self.tableView.tableHeaderView = trialHeaderView;
[trialHeaderView release];
}