I want to create a round circular button. This button should look like a circle.
This code gives round rectangular button.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(100, 100, 100, 30); UIImage *image = [UIImage imageNamed:@"01.png"]; [button setImage:image forState:UIControlStateNormal]; [image release];
I figured out how to create a rounded rectangular button but I want to create a round circle button. What do I need to change?
To create a rounded button you have to make use of the border-radius CSS property. The higher the value for that property the more rounder the corners will be. You can use any CSS unit for the boorder-radius property. It can be pixels, ems, rems, percentages etc.
Rounded corners HTML Buttons You can make rounded corners button by adding border-radius of 5px to 10px on HTML buttons.
Use the border-radius Property to Create a Circle Button in CSS. We can use the border-radius property to create a circle button in CSS. The property creates the rounded corners to the selected element by adding the radius to the element's corners.
Is there an easy way to achieve this in Android? Yes, today there is, and it is very simple. Just use the MaterialButton in the Material Components library with the app:cornerRadius attribute. It is enough to obtain a Button with rounded corners.
Tested Code:
.h
#import <QuartzCore/QuartzCore.h> -(void)roundButtonDidTap:(UIButton*)tappedButton;
.m
#define ROUND_BUTTON_WIDTH_HEIGHT YourButtonWidthToBeSetHere -(void)roundButtonDidTap:(UIButton*)tappedButton{ NSLog(@"roundButtonDidTap Method Called"); } UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"TimoonPumba.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(roundButtonDidTap:) forControlEvents:UIControlEventTouchUpInside]; //width and height should be same value button.frame = CGRectMake(0, 0, ROUND_BUTTON_WIDTH_HEIGHT, ROUND_BUTTON_WIDTH_HEIGHT); //Clip/Clear the other pieces whichever outside the rounded corner button.clipsToBounds = YES; //half of the width button.layer.cornerRadius = ROUND_BUTTON_WIDTH_HEIGHT/2.0f; button.layer.borderColor=[UIColor redColor].CGColor; button.layer.borderWidth=2.0f; [self.view addSubview:button];
Result
Geometry in this concept
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With