My goal is to have the first line with a centered text and the second line where it is, right-aligned.
Is this possible?
I used attributed strings passing NSParagraphStyleAttributeName
with the desired alignment but the UILabel
seems to consider only the last paragraph style.
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
// Mathemagika
paragraph.alignment = NSTextAlignmentCenter;
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]
initWithString:fullStr];
[attrStr addAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Noteworthy-Bold" size:30.f],
NSParagraphStyleAttributeName : paragraph}
range:NSMakeRange(0, fullStr.length)];
// ©
paragraph.alignment = NSTextAlignmentCenter;
NSAttributedString *attrStr2 = [[NSAttributedString alloc]
initWithString:@"©"
attributes:@{NSBaselineOffsetAttributeName : @20,
NSFontAttributeName : [UIFont fontWithName:@"Noteworthy-Bold" size:10.f],
NSParagraphStyleAttributeName : paragraph}];
[attrStr appendAttributedString:attrStr2];
// Interactive Math Formulae
paragraph.alignment = NSTextAlignmentRight;
NSAttributedString *attrStr3 = [[NSAttributedString alloc]
initWithString:@"\nInteractive Math Formulae\n"
attributes:@{NSFontAttributeName : [UIFont fontWithName:@"Noteworthy-Bold" size:10.f],
NSParagraphStyleAttributeName : paragraph}];
[attrStr appendAttributedString:attrStr3];
UILabel *titleLabel = [UILabel new];
[titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[titleLabel setAttributedText:attrStr];
titleLabel.backgroundColor = self.view.backgroundColor;
[view addSubview:titleLabel];