Использование Objective-C, вам необходимо сделать 4 NSMutableAttributedString с разными названиями шрифтов и размеров, а затем добавить их с помощью «appendAttributedString» для того, чтобы получить желаемый результат. Используя этот подход, вам нужно всего лишь создать один кадр для всех строк.
См. Приведенный ниже код для справки.
//frame that contains all text
textFrame = [[UILabel alloc] init];
[textFrame setTextAlignment:NSTextAlignmentCenter];
[textFrame setNumberOfLines:0];
[self.view addSubview:textFrame];
NSString *text1 = @"THE";
NSString *text2 = @"\nHAPPINESS OF";
NSString *text3 = @"\nYOUR LIFE";
NSString *text4 = @"\nDEPENDS UPON";
//change font name and size according to your need.
UIFont *text1Font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:10];
NSMutableAttributedString *attributedString1 =
[[NSMutableAttributedString alloc] initWithString:text1 attributes:@{
NSFontAttributeName : text1Font}];
NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setAlignment:NSTextAlignmentCenter];
[paragraphStyle1 setLineSpacing:4];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [attributedString1 length])];
UIFont *text2Font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:16];
NSMutableAttributedString *attributedString2 =
[[NSMutableAttributedString alloc] initWithString:text2 attributes:@{NSFontAttributeName : text2Font }];
NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle2 setLineSpacing:4];
[paragraphStyle2 setAlignment:NSTextAlignmentCenter];
[attributedString2 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, [attributedString2 length])];
UIFont *text3Font = [UIFont fontWithName:@"HelveticaNeue" size:14];
NSMutableAttributedString *attributedString3 =
[[NSMutableAttributedString alloc] initWithString:text3 attributes:@{NSFontAttributeName : text3Font }];
NSMutableParagraphStyle *paragraphStyle3 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle3 setAlignment:NSTextAlignmentCenter];
[attributedString3 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle3 range:NSMakeRange(0, [attributedString3 length])];
UIFont *text4Font = [UIFont fontWithName:@"HelveticaNeue" size:14];
NSMutableAttributedString *attributedString4 =
[[NSMutableAttributedString alloc] initWithString:text4 attributes:@{NSFontAttributeName : text4Font }];
NSMutableParagraphStyle *paragraphStyle4 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle4 setAlignment:NSTextAlignmentCenter];
[attributedString4 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle4 range:NSMakeRange(0, [attributedString4 length])];
[attributedString1 appendAttributedString:attributedString2];
[attributedString1 appendAttributedString:attributedString3];
[attributedString1 appendAttributedString:attributedString4];
[textFrame setAttributedText:attributedString1];
[textFrame sizeToFit];
//change frame size as per your need.
[textFrame setFrame:CGRectMake(10, 0, 136, 97)];
Использование NSAttributedString с label.attributedText вместо label.text – RJE
я использовал NSAttributed строку, но не делают надлежащего формиат, как это ..so предложить другой метод option..or – Keyur