57

私のビルドターゲットは、私が理解しているIOS5に設定されていUIButton.tintColorます...

View ControllerのviewDidLoadにこれがあります

[timelineButton setTintColor:[UIColor blackColor]];
[timelineButton setTitle:@"test" forState:UIControlStateNormal];

テキストは適切に変更されますが、ボタンは黒ではありませんか?

ありがとう!

4

13 に答える 13

67

ドキュメントによると:

このプロパティは、すべてのボタン タイプに対して有効というわけではありません。

これらのbuttonType別のものに切り替える必要があります。(残念ながら、ドキュメントでは、このプロパティをサポートする特定のボタンの種類は指定されていません。)

于 2012-06-16T18:34:21.760 に答える
39

ボタンの「タイプ」がシステムに設定されていることを確認してください。カスタムに設定されている場合、ボタンの色が変化しないことが原因である可能性があります。これが私に起こったことであり、タイプをシステムに変更すると修正されました。

于 2015-02-09T20:14:10.937 に答える
8

ハイライトされた州の色に色を付けます。UIButton をタップまたはクリックすると、UIButton をタップまたはクリックしている間、tintColor で指定された色が表示されます。

resetButton.tintColor = [UIColor colorWithRed:0.764 green:1.000 blue:0.000 alpha:1.000];

ボタンは通常の状態では白です。しかし、ボタンをタップすると色が赤に変わりますが、それはその時だけです。

ボタンを変更する必要がある場合は、UIControlStateNormal で赤または青のように見えます。

Interface Builder またはプログラムで UIButtonType を UIButtonTypeCustom に変更します。

 UIButton *resetButton = [UIButton buttonWithType:UIButtonTypeCustom];

自分で属性を変更し、丸みを帯びた角を再作成します

resetButton.backgroundColor = [UIColor redColor];
resetButton.layer.borderColor = [UIColor blackColor].CGColor;
resetButton.layer.borderWidth = 0.5f;
resetButton.layer.cornerRadius = 10.0f;
于 2012-10-15T21:21:54.580 に答える
7

他の回答で述べたように、色合いはカスタムボタンタイプでは機能しません。ボタンの型を明示的に宣言していることを確認してください。[UIButton alloc] init] だけを使用しないでください

これはうまくいきます:

UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mybutton setImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal];
mybutton.tintColor = [ODTheme blueTintColor];
于 2013-12-04T20:13:43.377 に答える
4

今日、私もこの問題に遭遇しました。デリゲートを使用して解決します。

[button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(buttonPressReset:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];

-(void)buttonPress:(id)sender{
UIButton* button = (UIButton*)sender;
[button setBackgroundColor:[UIColor greenColor]];
NSLog(@"buttonPressed");
}

-(void)buttonPressReset:(id)sender{
UIButton* button = (UIButton*)sender;
[button setBackgroundColor:[UIColor redColor]];
NSLog(@"buttonPressReset");
}
于 2013-01-08T06:01:24.073 に答える
3

この方法を試してください:

- (void)setTitleColor:(UIColor *)color
             forState:(UIControlState)state
于 2016-02-15T23:15:18.933 に答える
1

ボタンのテキストの色を変更するには、次を使用できます。

resetButton.setTitleColor(UIColor.blackColor(), forState: .Normal)

または OBJ-C:

- (void)setTitleColor:(UIColor *)color
         forState:(UIControlState)state

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instm/UIButton/setTitleColor:forState :

于 2016-05-13T10:16:56.397 に答える