How can I change UIButton title color?

前端 未结 5 1837
無奈伤痛
無奈伤痛 2020-12-04 09:14

I create a button programmatically..........

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
fo         


        
5条回答
  •  一生所求
    2020-12-04 09:49

    You can use -[UIButton setTitleColor:forState:] to do this.

    Example:

    Objective-C

    [buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    

    Swift 2

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

    Swift 3

    buttonName.setTitleColor(UIColor.white, for: .normal)
    

    Thanks to richardchildan

提交回复
热议问题