То, что я сделал в одном из моих приложений, это для создания текста так:
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 для ширины ограничения, чтобы обозначить границы надписей с обеих сторон. Затем я использовал растягиваемое изображение, как это:
![UITableViewHeaderImage](https://i.stack.imgur.com/z3poH.png)
И масштабировал его так, чтобы он соответствовал тексту в заголовке:
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;