我的方法:無法設置的UITableView細胞標籤背景顏色和文本對齊
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSInteger row = indexPath.row;
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
// Setup row background image (a.k.a the set image)
NSString *setID = [[self.wallpaperCollectionArray objectAtIndex:row] valueForKey:@"id"];
NSString *setImageName = [@"s-" stringByAppendingString:setID];
UIImage *setImage = [UIImage imageNamed:setImageName];
cell.backgroundView = [[UIImageView alloc] initWithImage:setImage];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:setImage];
NSString *setName = [[self.wallpaperCollectionArray objectAtIndex:row] valueForKey:@"name"];
cell.textLabel.text = [setName uppercaseString];
cell.textLabel.font = [UIFont fontWithName:@"OpenSans" size:20];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor redColor]; // Not working?
cell.textLabel.textAlignment = NSTextAlignmentCenter; // Not working?
return cell;
}
然而,結果是相當怪異,其中backgroundColor
和textAlignment
沒有得到應用。
這是一個編程方式創建的UITableView。我該怎麼辦?
UPDATE:背景顏色問題已解決。仍然難以對中。
你的部署目標是什麼? –
我相信[這篇文章是相同的問題](http://stackoverflow.com/questions/1164459/changing-uitableviewcell-textlabel-background-color-to-clear),並會幫助你。 – Mick
http://stackoverflow.com/questions/2610547/textlabel-backgroundcolor-on-uitableviewcell-does-not-work –