As NSAttributedString
is primarily used with Core Text on iOS, you have to use CTParagraphStyle
instead of NSParagraphStyle
. There is no mutable variant.
For example:
CTTextAlignment alignment = kCTCenterTextAlignment;
CTParagraphStyleSetting alignmentSetting;
alignmentSetting.spec = kCTParagraphStyleSpecifierAlignment;
alignmentSetting.valueSize = sizeof(CTTextAlignment);
alignmentSetting.value = &alignment;
CTParagraphStyleSetting settings[1] = {alignmentSetting};
size_t settingsCount = 1;
CTParagraphStyleRef paragraphRef = CTParagraphStyleCreate(settings, settingsCount);
NSDictionary *attributes = @{(__bridge id)kCTParagraphStyleAttributeName : (__bridge id)paragraphRef};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Hello World" attributes:attributes];