嗨我有一个tableview的问题。单元格textlabel(默认原型单元格)隐藏了我背景的一部分。我不明白为什么以及如何改变。
我知道我可以修复自己的标签,但我想知道这里的错误在哪里。
这是应该如何,底部有一条线......作为分隔线
但这是它出现的方式
这是代码
- (void)viewDidLoad
{
[super viewDidLoad];
icons = [NSArray arrayWithObjects:
@"No Icon",
@"Appointments",
@"Birthdays",
@"Chores",
@"Drinks",
@"Folder",
@"Groceries",
@"Inbox",
@"Photos",
@"Trips",
nil];
rowImage = [NSArray arrayWithObjects:@"row", @"row2", @"row3", @"row4", nil];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
self.tableView.tableFooterView = [[UIView alloc] init];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [icons count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IconCell"];
NSString *icon = [icons objectAtIndex:indexPath.row];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[rowImage objectAtIndex:arc4random()%4]]];
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.bounds = CGRectMake(cell.textLabel.frame.origin.x, cell.textLabel.frame.origin.y, cell.textLabel.frame.size.width, 10);
cell.textLabel.frame = CGRectMake(cell.textLabel.frame.origin.x, cell.textLabel.frame.origin.y, cell.textLabel.frame.size.width, 10);
cell.textLabel.text = icon;
cell.imageView.image = [UIImage imageNamed:icon];
return cell;
}
答案 0 :(得分:0)
尝试下一步:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.backgroundColor = [UIColor clearColor];
}