Search code examples
iosobjective-ccocoansattributedstring

NSTextList in iOS


Is there an equivalent for NSTextList on iOS?

On OSX i can do

NSTextList *list = [[NSTextList alloc] initWithMarkerFormat:@"square" options:0];
NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraph setTextLists:[NSArray arrayWithObject:list]];
NSTextTab *t1 = [[NSTextTab alloc] initWithType:0 location:11.0f];
NSTextTab *t2 = [[NSTextTab alloc] initWithType:0 location:36.0f];
[paragraph setTabStops:[NSArray arrayWithObjects:t1, t2, nil]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph, NSParagraphStyleAttributeName, nil];
NSString *string = @"\t▪\tList item 1\n\t▪\tList item 2\n\t▪\tList item 3";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string attributes:attributes];

but there isn't an alternative for iOS, as all the solutions doesn't behave correctly


Solution

  • I know this is a late answer but it might be beneficial to people in the future.

    Yes, you can in fact simply use NSTextList itself.

    As it turns out, NSTextList has been included in iOS since at least iOS 7 (see Apple documentation and iOS header dumps).

    However, it hasn't been in the SDK for whatever reason until iOS 16.

    You can copy the header from an SDK that has it into /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk/System/Library/Frameworks/UIKit.framework/Headers.

    Alternatively, I think you could forward-declare the @interface for the NSTextList methods you want to use.