Cocoa Touch - Color of a round rectangular button?

Do they still change the white part of the round rectangular button without creating a custom button?

+3
source share
3 answers

Almost. You must configure it to custom, but without a subclass of UIButton. Then you can do something like

myButton.layer.cornerRadius = 8;
myButton.layer.backgroundColor = [[UIColor blueColor] CGColor];

You can also adjust the thickness and color of the border this way. See the CALayer documentation for more details .

+5
source

I don’t know why someone refused this answer, it works fine, but you have to add the QuartzCore structure and

    #import <QuartzCore/QuartzCore.h> 

, , , , , .

+4

As Oliver mentioned, the easiest way to solve this problem is to create your own custom UIButton with a custom type

// initialize your own UIButton
UIButton *myBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// set background color
[myBtn setBackgroundColor:[UIColor blackColor]];
// set corner radius
myBtn.layer.cornerRadius = 8;

Remember to import the Quartzcore framework into your .m implementation file. Otherwise, you will not be able to set the cornerRadius of your custom button.

#import <QuartzCore/QuartzCore.h>
+3
source

Source: https://habr.com/ru/post/1758650/


All Articles