我的方法:
- (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。我该怎么办?
更新:背景颜色问题已解决。仍然难倒居中。