誰でも私のために何かをチェックしてもらえますか...私が怒っていないことを確認するために!
NSMutableParagraphStyle
withを作成しましたがtabStops
、期待していた場所に表示されませんでした:
float width = self.myLabel.frame.size.width;
self.tabStyle.tabStops = @[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width - 50 options:nil],
[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width options:nil]];
次に、2 つの文字列のタブ位置を持つ属性付き文字列を作成する便利なメソッドを作成しました。
- (NSAttributedString *)tabbedTextWithFirstString:(NSString *)firstString secondString:(NSString *)secondString
{
NSDictionary *attributes = @{NSFontAttributeName:[UIFont fontWithName:kHSTFontFaceDefault size:14.0]};
NSString *tabbedStr = [NSString stringWithFormat:@"\t%@\t", firstString];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:tabbedStr attributes:attributes];
attributes = @{NSFontAttributeName:[UIFont fontWithName:kHSTFontFaceDefaultBold size:14.0]};
[attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:secondString attributes:attributes]];
[attrStr addAttribute:NSParagraphStyleAttributeName value:self.tabStyle range:NSMakeRange(0, attrStr.length)];
return attrStr;
}
これは、上下に表示される 2 つの別々UILabel
の に適用されていました。コードを実行してテキストを挿入すると、最初の文字列は中央揃えに見え、2 番目の文字列はラベルの端から切り取られていました。
それで、 に変更NSTextAlignmentRight
したところNSTextAlignmentCenter
、正しく正しく配置されました。
私は自分の問題を解決したことを知っていますが、iOS フレームワークに間違いがあるように見えるので、Apple がこの問題を修正したとしてもアプリが壊れないようにしたいと思っています。ですから、それが本当に間違っているのか、それとも私が実際に間違っているのかを誰かが教えてくれたら、とても感謝しています、ありがとう!