textviewcell标签涵盖了我的背景

时间:2013-10-15 15:35:29

标签: objective-c xcode tableview tableviewcell

嗨我有一个tableview的问题。单元格textlabel(默认原型单元格)隐藏了我背景的一部分。我不明白为什么以及如何改变。

我知道我可以修复自己的标签,但我想知道这里的错误在哪里。



这是应该如何,底部有一条线......作为分隔线

here is how it should be, with a line on the bottom... as a divider



但这是它出现的方式

enter image description here



这是代码

- (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;
}

1 个答案:

答案 0 :(得分:0)

尝试下一步:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.textLabel.backgroundColor = [UIColor clearColor];
}