2

次のコードを使用して、xcodeにUIボタンを追加するときに、タイトルラベルのテキストの色、配置、およびフォントサイズを設定しています。フォントサイズは選択されますが、テキストの色と配置は選択されません。なぜですか?ありがとう。

toButton.titleLabel.textColor = [UIColor redColor];
toButton.titleLabel.textAlignment = UITextAlignmentRight;
toButton.titleLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
[toButton setTitle:fromButton.titleLabel.text forState:UIControlStateNormal];
4

1 に答える 1

7

titleLabelこれの代わりに色を設定しています。次を使用します。

[toButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

テキストの配置には、次の行が機能します。

toButton.titleLabel.textAlignment = UITextAlignmentRight;

以下も使用できます。

toButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
于 2012-08-23T17:15:22.420 に答える