Hi,
I am writing for the first time on FindNerd. Many times we need to make buttons, labels, imageview, view to have rounded corner. and we write code as below to perform it.
[redButton.layer setCornerRadius:15.0f];
[redButton.layer setMasksToBounds:YES];
[redButton.layer setBorderColor:[UIColor blueColor].CGColor];
[redButton.layer setBorderWidth:1];
You can achieve the same behavior from XIB also.
- Open XIB and drag a button or a UIView on to the canvas.
Select the button or UIView and click on Show/Hide utilities
Click on Show Identity Inspector
Below that you will find a section named "User Defined Runtime Attributes"
Click + button and enter the following values:
Key Path - layer.cornerRadius
Type - NSNumber
Value - 15
Do this 3 more times and enter the values as shown in screenshot below:
You may find that in 3rd value, it is layer.borderIBColor. This is because in few UI components we cannot give a direct color rather we have to give color.CGColor as shown above while doing it from code.
I have created a category on CALayer. You can download the files and include it in project.
Once you have set everything you can Run the application. You will find that the corners are rounded now.
If you don't find it in iOS 7 give a background color to UIButton/UIView.
Please test and give your comments.
0 Comment(s)