Uitableviewcell Textlabel Color Not Changing

UITableViewCell textLabel color not changing

It's because of this:

cell.userInteractionEnabled = NO;

If you don't want your cells to be selectable, try using this instead:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

UITableView cell textLabel color

Got the solution
by setting color in if (cell == nil) check

if (cell == nil) 
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor whiteColor];
}

and

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor orangeColor];

}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor whiteColor];

}

Thanks

UITableViewCell textColor will not change with userInteractionEnabled = NO

Ok I know how to fix this but it does NOT make any sense at all, the problem is this line:

cell.userInteractionEnabled = NO;

If removed the textColor changes, the odd thing is that if i change the user interaction at the end after changing the textColor the color changes!

Is this a bug?. I hope this answer helps anyone trying to figure this out as it does not make any sense at all, and there is no documentation about this.

Dynamically changing textColor of a UITableViewCell's text

you could use selectedRowIndex as a class-level variable, and just keep updating that every time you select a row. Initially - whether selected or not - this should be 0, so that the first row is different

I think you don't want to use the text value because it may not be unique

What happens when you make multiple selections without leaving the view? Presumably you need to clear the white text from the old row, and set it again on the new one?

Easiest way to implement that is going to be reloading the tableView on each selection - but if that takes too long, you could always reload the individual rows - on row selection set selectedRowIndexPrevious before you update selectedRowIndex, and reload both of those rows. The previous row will redraw in grey, and the new one in white

here's how you might implement some of this

class MyViewController : UIViewController
{
// define the variables to keep track of row selection here
var selectedRowIndex : Int = 0
var selectedRowIndexPrevious : Int = -1

// the rest of your code

and then you need to update the selectedRow variables

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Uncheck the previous checked row
selectedRowIndexPrevious = selectedRowIndex

// **UPDATED** need to set the selectedRowIndex
selectedRowIndex = indexPath.row
// **UPDATED**

// reload needs an array of indexPath
// so we can supply the previous selection AND the current one

NSIndexPath* rowToReloadPrevious = [NSIndexPath indexPathForRow: selectedRowIndexPrevious inSection:0];
NSIndexPath* rowToReloadNew = [NSIndexPath indexPathForRow: selectedRowIndex inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReloadPrevious, rowToReloadNew, nil];
[tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
}

within the cellForRowAtIndexPath, you just need to look at selectedRowIndex instead of checking the text

if (indexPath.row == selectedRowIndex) {
cell.textLabel.textColor = [UIColor whiteColor];
} else {
cell.textLabel.textColor = [UIColor grey1Color];
}

}

UITableViewCell appearance not changing textLabel font

Setting the font property of a UITableViewCell is not supported using the appearance proxy.

You can tell which properties are supported by looking in the header file for that class for UI_APPEARANCE_SELECTOR.

Take a look at UITableViewCell.h and you'll see that only separatorInset is supported (and backgroundColor as this is supported by its superclass, UIView):

@property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the separator frame


From the UIAppearance protocol reference:

To support appearance customization, a class must conform to the UIAppearanceContainer protocol and relevant accessor methods must be marked with UI_APPEARANCE_SELECTOR.

How to change the color of text in a tableview swift?

First, I don't think it's wise to use appearance() to globally alter all your cells, but if you do it, you should be, as your link says, calling it in your AppDelegate, not each time you load a cell.

Second, you can customize many of these features directly in storyboard (and since you're using a reusable cell, you really should) - go find your cell and change the text color there.

Or, as mentioned by @Umair, you can simply change that call to not be global, and change the color directly.

UITableViewCell Detail Text Label Text Color

I had the same issue and logged a bug report in the Apple Bug Reporter. My bug report was closed with the comments "Duplicate of 28317724 (Open)". I am not sure if bug reports other than your own are visible, the system does not appear to be very transparent.

Change the text colors of all UITableViewCells using UIAppearance

You're doing the right thing, but there's no way for iOS to distinguish between those two labels using UIAppearance. You should either set the text colour in willDisplayCell, or, if you really want to use UIAppearance, create custom UILabel subclasses that you can target more accurately.

If you want to use willDisplayCell, it would look something like this:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.textColor = [UIColor redColor];
}

Alternatively, you might also find this answer has some other ideas.

How can I change text color of certain cells in UITableView?

After the var items declaration, add this:

let itemColors = [UIColor.greenColor(), UIColor.redColor()]

In tableView(_:cellForRowAtIndexPath:), add this before the return statement:

cell.textLabel?.textColor = itemColors[indexPath.row]


Related Topics



Leave a reply



Submit