我想画一个UITextView
包括一些文本的内部可定制线(使用NSAttributedString
)绘制一个UITextView内的线路 - NSAttributedString
这里就是我试图
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];
但无论什么样的价值我提供制表位位置(在这种情况下为40)和tailIndent(这里为-16),该行仅尊重headIndent并跨越整个UITextView宽度(当然不包括headIndent)。
编辑 - 我很确定这个问题是因为我没有使用正确的Unicode字符(虽然他们似乎是合乎逻辑的选择)。如果这给了某人一个提示,如果我在第二个nbsp之后添加一个空格,即结束,则该选项卡被限制为单个标签长度
你能提供一个你想让文字看起来像什么的例子吗? –
我试图实施hr标签(水平线)。从html转换时,它们不受NSAttributedString支持 – lostInTransit