I want to draw a custom string inside a UITextView consisting of some text (using NSAttributedString )
Here is what I tried
NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr]; NSRange strRange = NSMakeRange(0, str.length); NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init]; tabStyle.headIndent = 16; //padding on left and right edges tabStyle.firstLineHeadIndent = 16; tabStyle.tailIndent = -16; NSTextTab *listTab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentCenter location:40 options:@{}]; //this is how long I want the line to be tabStyle.tabStops = @[listTab]; [str addAttribute:NSParagraphStyleAttributeName value:tabStyle range:strRange]; [str addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:strRange];
But no matter what value I provide for the tab stop (in this case 40) and tailIndent (-16 here), the line only considers the title and covers the entire width of the UITextView (minus headIndent, of course).
EDIT . I'm sure the problem is that I am not using the correct Unicode characters (although they seem like a logical choice). If this gives someone a hint, if I add a space after the second nbsp, that is, towards the end, the tab will be limited to one tab length
ios objective-c nsattributedstring
lostInTransit
source share