My method:
- (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;
}
Nevertheless, the result is rather weird, where the backgroundColor
and textAlignment
do not get applied.
This is a programmatically created UITableView. What should I do?
UPDATE: the background color issue is solved. Still stumped with the centering.