Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel shadow from custom cell selected color

I'm loading a custom nib file to customize the cells of a UITableView. The custom nib has a UILabel that is referenced from the main view by tag. I would like to know if it is possible to change the shadow color of the UILabel when the cell is selected to a different color so it doesn't look like in the screenshot.

screenshot

like image 746
Iñigo Beitia Avatar asked Aug 08 '10 22:08

Iñigo Beitia


2 Answers

I prefer to make the shadow color change inside the TableCell code to not pollute the delegate. You can override this method to handle it:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animate
{
    UIColor * newShadow = highlighted ? [UIColor clearColor] : [UIColor whiteColor];

    nameLabel.shadowColor = newShadow;

    [super setHighlighted:highlighted animated:animate];
}
like image 130
Jason Avatar answered Oct 27 '22 11:10

Jason


You could change the label's shadow color in -tableView:willSelectRowAtIndexPath: in the delegate. For instance:

-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.shadowColor = [UIColor greenColor];
    return indexPath;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.shadowColor = [UIColor redColor];
}
like image 25
kennytm Avatar answered Oct 27 '22 11:10

kennytm