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 を差し引いたもの) にまたがります。
編集-正しいユニコード文字を使用していないため、問題が発生していると確信しています(ただし、それらは論理的な選択のようです)。これが誰かにヒントを与える場合、2番目のnbspの後にスペースを追加すると、つまり最後に向かって、タブは単一のタブの長さに制限されます