Coloration of UIButtons of type UIButtonTypeRoundedRect

后端 未结 4 1294
闹比i
闹比i 2021-01-19 14:38

I would like the rounded rectangle portion of the subject type of UIButton to be a solid custom color I specify. I understand that

. setTitleColor : changes the tex

4条回答
  •  被撕碎了的回忆
    2021-01-19 15:17

    You can try to grab the layer and set its corner radius in a custom button. I haven't tried it, but it seems worth a try.

    [[button layer] setCornerRadius:12.0f];
    [[button layer] setMasksToBounds:YES];
    [[button layer] setBackgroundColor:[[UIColor redColor] CGColor]];
    

    You'll have to add the QuartzCore framework to your project (and #import ) in order to take advantage of these methods.

    Just an addition, in this case you use button type as "Custom". So the button can be declared as : UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

提交回复
热议问题