Reputation: 69
*I have this answers here : Correct with help of **Yossi How to put buttons over UITableView which won't scroll with table in iOS***
I know answers work with NavigationControllerController
[self.navigationController.view addSubview:_btnCircle];
I learned to write in Objective C iOS app. Please help me to implement to get the Circle button display on uitableview as shown below. Or help me search keywords.
Example 1:
Example 2:
Upvotes: 3
Views: 10490
Reputation: 16052
For Swift:
button.layer.masksToBounds = true
button.layer.cornerRadius = self.frame.width / 2
If you are creating a custom UIButton
(or a custom UIView
), implement the following inside the custom class:
override func layoutSubviews() {
super.layoutSubviews()
self.layer.masksToBounds = true
self.layer.cornerRadius = self.frame.width / 2
}
Upvotes: 0
Reputation: 10096
The simplest way is to add QuartzCore Framework
#import <QuartzCore/QuartzCore.h>
and then use the following code for your button:
button.layer.cornerRadius = 0.5 * button.bounds.size.width;
Now you have the round button from the square one.
Upvotes: 12
Reputation: 1091
In order to make any button round you need to set the cornerRadius property of the button.
Note- In order to make circle you need to make sure that height and width are equal and radius is set half of the width/height. This will make perfect round circle.
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(10, 10, 50, 50)];
btn.layer.cornerRadius = 0.5 * btn.bounds.size.width;
Upvotes: 4