ボタンにタイトルを2色で設定したい。
下の画像と同じでしょうか?
どんな助けでも大歓迎です。
前もって感謝します。
ストーリーボード: スクリーンショットに従ってください。
プログラムの場合:属性付きテキストについては、ここにすでに多くの回答の投稿があります。UIButton に BackgroundImage を配置する場合は、プログラムでボタンの背景画像 iPhone を設定します。
これを試して
NSMutableAttributedString *mutableString = [[NSMutableAttributedString alloc] initWithString:@"ThisIsAttributed"];
[mutableString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,4)];
[mutableString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(5,2)];
[button setAttributedTitle:mutableString forState:UIControlStateNormal];
5.0 未満の iOS
およびNSMutableAttributedString
現在の iOS バージョンで使用できます。
[button setAttributedTitle:someAttributedText forState:UIControlStateNormal];