Ответ 1
Цвет фона заголовка раздела tableview по умолчанию для ios7 равен
Objective-C
[UIColor colorWithRed:247/255.0f green:247/255.0f blue:247/255.0f alpha:1.0f]
Swift
UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1)
Я хочу настроить заголовок раздела TableView и оставить цвет фона по умолчанию. Я использую - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)
. Мне нужно изменить размер шрифта в зависимости от устройства (iPad или iPhone). Для этого вызовите следующую функцию:
[UIColor colorWithHue: 0,6 насыщенность: 0,33 яркость: 0,69 альфа 0,6].
Но я нашел эти значения вручную.
Цвет фона заголовка раздела tableview по умолчанию для ios7 равен
Objective-C
[UIColor colorWithRed:247/255.0f green:247/255.0f blue:247/255.0f alpha:1.0f]
Swift
UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1)
Для фона изменения Цвет заголовка TableView в разделе "Только одна строка"
добавить TableView
делегат willDisplayHeaderView
:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
**header.tintColor = [UIColor whiteColor];**
}
Objective-C:
[UIColor colorWithRed:232/255.0f green:233/255.0f blue:237/255.0f alpha:1.0f]
Swift:
UIColor(red: 232/255, green: 233/255, blue: 237/255, alpha: 1)
Что я сделал в одном из моих приложений, так это создать текст:
NSString *sectionTitle = @"YOUR TITLE HERE";
CGSize sz = [sectionTitle sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]
constrainedToSize:CGSizeMake(290.0f, 20000.0f)
lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(sz.height, 20.0f);
CGRect sectionFrame = CGRectMake(0.0, 0.0, 320.0, height);
Я использовал 290 для ширины ограничения, чтобы выставлять метки с обеих сторон. Затем я использовал растягиваемое изображение следующим образом:
И масштабировал его, чтобы он соответствовал тексту в заголовке:
UIImage *headerImage = [UIImage imageNamed:@"sectionheaderbackground.png"];
UIImage *stretchableImage = [headerImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:sectionFrame];
backgroundImageView.image = stretchableImage;
// Add it to the view for the header
UIView *sectionView = [[UIView alloc] initWithFrame:sectionFrame];
sectionView.alpha = 0.9;
sectionView.backgroundColor = [UIColor clearColor];
[sectionView addSubview:backgroundImageView];
Наконец, я создал ярлык и добавил его как подвью:
CGRect labelFrame = CGRectMake(10.0, 0.0, 290.0, height);
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:labelFrame];
sectionLabel.text = sectionTitle;
sectionLabel.numberOfLines = 0;
sectionLabel.font = [UIFont boldSystemFontOfSize:18.0];
sectionLabel.textColor = [UIColor whiteColor];
sectionLabel.shadowColor = [UIColor grayColor];
sectionLabel.shadowOffset = CGSizeMake(0, 1);
sectionLabel.backgroundColor = [UIColor clearColor];
[sectionView addSubview:sectionLabel];
return sectionView;
для iOS 11 я выбрал цвет на симуляторе.
объект c: [UIColor colorWithRed: 247/255,0 зеленый: 247/255,0 синий: 247/255,0 альфа: 1,0]
swift: UIColor (красный: 247/255,0, зеленый: 247/255,0, синий: 247/255,0, альфа: 1,0)
Но нам нужно менять всякий раз, когда Apple меняет цвет.
Как получить цвет заголовка раздела по умолчанию?
Шестнадцатеричный цвет - # e8e9ed
Цвет RGB - UIColor (красный: 232/255, зеленый: 233/255, синий: 237/255, альфа: 1)
или вы можете использовать # f7f7f7