iPhone : How to set BackgroundColor of UIButton with buttonType UIButtonTypeCustom

前端 未结 15 1466
有刺的猬
有刺的猬 2020-12-01 13:45

i want to change the button color when it is clicked. I used :

[button setBackgroundColor:[UIColor redColor]];

but this shows red color onl

15条回答
  •  误落风尘
    2020-12-01 14:43

    You have everything correct. Just set your button type to UIButtonTypeCustom..

    button =    [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame    =   CGRectMake(200, 8, 100, 30);
    [button setTitle:@"Set up" forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor greenColor]];
    button.clipsToBounds    =   YES;
    button.layer.cornerRadius   =   10;
    button.alpha        =   0.5;
    

提交回复
热议问题