2016-03-24 11 views
2

NSAttributedStringを使用してテキストのフォントサイズを変更しようとしています。サイズは変わりません。目的c UIFont systemFontOfSizeが機能しない

NSDictionary *attrDict = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:22], NSForegroundColorAttributeName : [UIColor orangeColor]}; 

NSAttributedString *newAttString = [[NSAttributedString alloc] initWithString:mytext attributes:attrDict]; 

[result appendAttributedString:newAttString]; 

テキストの色のみが変更されます。結果の文字列のサイズは22ではなく、太字でもありません。代わりのallocと属性を適用する

+0

ログに 'newAttString'の値が正しいようですか? 'newString'も追加した後の' result'の1つですか?あなたの問題はその後になる可能性があります。 – Larme

+0

文字列が正しい。エラーはありません。しかし、フォントサイズは変わりません。 – user

+0

後で 'result'をどうしますか?どこかで 'NSFontAttributeName'をもう一度適用しますか? – Larme

答えて

0

、INIT、後(可変 NSAttributedString付き)のようなものでそれをやってみてください。

NSMutableAttributedString *newAtt = [[NSMutableAttributedString alloc] initWithString:mytext]; // Allocate a new NSMutableAttributedString with `mytext` 
[newAtt addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:20], 
             NSForegroundColorAttributeName: [UIColor orangeColor]} 
           range:NSMakeRange(0, [result length])]; // add new attributes for the length of the string `mytext` 

[result setAttributedText:newAtt]; 

この答えはresultが何であるかに依存して変化する、私がテストしましたそれはUITextViewにあり、うまくいきました。attributedText というプロパティがUILabelsにあります。 これが役立つことを願っています。

0

あなたのコードの最後には、の意味がありませんでした。あなたはそれを "追加"してもよろしいですか?

はほかに、私は、これは、それぞれ異なるフォントやサイズを設定するために使用できるフォントに

[UIFont fontWithName:@"Arial-BoldMT" size:22.0f] 

を設定するために、このコードを使用します。

希望します。

関連する問題