Những gì tôi đã làm trong một trong những ứng dụng của tôi là tạo ra các văn bản như vậy:
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);
tôi đã sử dụng 290 cho chiều rộng hạn chế để cung cấp cho học sinh nội trú nhãn ở hai bên. sau đó tôi đã sử dụng một hình ảnh căng ra như thế này:

Và quy mô nó để phù hợp với văn bản trong tiêu đề:
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];
Cuối cùng, tôi đã tạo ra một nhãn và thêm nó như là một subview:
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;
Như tất cả các thành phần màu sắc giống hệt nhau (247/255), một sự thay đổi đơn giản hơn người bản xứ là: 'UIColor (trắng: 0,97, alpha: 1)' nơi 0,97 ~ 247/255 –