Как изменить цвет текста для заголовков разделов в Grouped TableView в iPhone SDK?

Кроме того, не забывайте выходить из переменных, если Вы хотите взять их от узла назначения.

Это ловило меня в прошлом.

, Например:

user@host> ssh user2@host2 "echo \$HOME"

распечатывает/home/user2

, в то время как

user@host> ssh user2@host2 "echo $HOME"

распечатывает/home/user

Другой пример:

user@host> ssh user2@host2 "echo hello world | awk '{print \$1}'"

распечатывает "привет" правильно.

22
задан halfer 24 September 2018 в 22:51
поделиться

3 ответа

Если вы не хотите делать это во всем приложении, как в решении Вахана, вот решение, использующее один из методов UITableViewDelegate:

func tableView(tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
    if let headerView = view as? UITableViewHeaderFooterView {
       headerView.textLabel?.textColor = UIColor.redColor() 
    }
}
34
ответ дан 29 November 2019 в 03:18
поделиться
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  UILabel *myLabel = [[UILabel alloc] init];
  myLabel.frame = CGRectMake(20, 8, 220, 20);
  myLabel.font = [UIFont boldSystemFontOfSize:16];
  myLabel.text = [self tableView:tableView 
  titleForHeaderInSection:section];
  myLabel.backgroundColor=[UIColor grayColor];
  UIView *headerView = [[UIView alloc] init];
  [headerView addSubview:myLabel];
  return headerView;
  }
2
ответ дан 29 November 2019 в 03:18
поделиться

Я построил ответ от @Harsh.

Это самое близкое, что я могу получить, неотличимо от того, что я могу сказать.

Это входит в < UITableViewDataSource > очевидно.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *hView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
    hView.backgroundColor=[UIColor clearColor];

    UILabel *hLabel=[[[UILabel alloc] initWithFrame:CGRectMake(19,17,301,21)] autorelease];

    hLabel.backgroundColor=[UIColor clearColor];
    hLabel.shadowColor = [UIColor whiteColor];
    hLabel.shadowOffset = CGSizeMake(0.5,1);  // closest as far as I could tell
    hLabel.textColor = [UIColor blackColor];  // or whatever you want
    hLabel.font = [UIFont boldSystemFontOfSize:17];
    hLabel.text = @"Your title here";  // probably from array

    [hView addSubview:hLabel];

    return hView;
}
2
ответ дан 29 November 2019 в 03:18
поделиться