Naved
Naved

Reputation: 4138

Making text color of UILabel same as UITableView header's text color

For one of my application, I have added UILabel to the UITableView header section.
But I want the text color of UILabel should also be the same as what it is displayed for table's header section (some gray shades).
How can I do this?

Thanks in advance.

Upvotes: 0

Views: 412

Answers (2)

Naved
Naved

Reputation: 4138

I got a workaround.

From one of stack-overflow question, I got a RGB value (RGB: 76, 86, 108 with font style BOLD and size is 16) for the text color used by UITableView's Header section. I am currently using the same for setting the text color of UILabel.

I would appreciate if one can tell me the way to know the textColor of UITableView programmatically so that the hard code RGB values will not be used.

Thank you for your support.

Upvotes: 1

javieralog
javieralog

Reputation: 1337

try to traverse UITableView subviews hierarchy looking for UILabels and then logging its attributes:

-(void)traverseView:(UIView *)view{
  for(UIView *subview in view.subviews){
    if ([subview isKindOfClass:[UILabel class]]){
      NSLog(@"font:%@",[(UILabel *)subview font]);
      NSLog(@"color:%@",[(UILabel *)subview textColor]);
      NSLog(@"and so on:%@",[(UILabel *)subview anotherProperty]);
    }else{
      [self traverseView:subview];
    }
  }
}

-(void)lookForIt:(UITableView *)tableView{
  [self traverseView:tableView];
}

Upvotes: 1

Related Questions