2

誰でも私のために何かをチェックしてもらえますか...私が怒っていないことを確認するために!

NSMutableParagraphStylewithを作成しましたが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 がこの問題を修正したとしてもアプリが壊れないようにしたいと思っています。ですから、それが本当に間違っているのか、それとも私が実際に間違っているのかを誰かが教えてくれたら、とても感謝しています、ありがとう!

4

1 に答える 1

0

私はこれに遭遇したばかりで、2015 年 8 月 21 日の時点で NSTextAlignmentCenter と NSTextAlignmentRight が入れ替わっていることを確認できます。

于 2015-08-21T16:03:01.303 に答える