Why is my UIButton.tintColor not working?

后端 未结 13 1073
长情又很酷
长情又很酷 2020-12-03 04:15

My build target is set for IOS5 which is where I understand UIButton.tintColor was introduced...

I have this in my viewDidLoad for the View Controller

13条回答
  •  北海茫月
    2020-12-03 04:59

    It tint your highlighted State color. When you tap/click on the UIButton the color specified with tintColor appears as long as you hold the tap/click on the UIButton.

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

    The button is white in normal state. But if I tap on the button the color turns red, but only then.

    IF you need to change the button so it looks like a red or blue one in the UIControlStateNormal then

    Change the UIButtonType to UIButtonTypeCustom in Interface Builder or programmatically with

     UIButton *resetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    

    Change the attributes on your own and recreate the rounded corners

    resetButton.backgroundColor = [UIColor redColor];
    resetButton.layer.borderColor = [UIColor blackColor].CGColor;
    resetButton.layer.borderWidth = 0.5f;
    resetButton.layer.cornerRadius = 10.0f;
    

提交回复
热议问题