Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a round button?

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?

like image 293
crazy2431 Avatar asked Aug 05 '11 07:08

crazy2431


People also ask

How do you make a round shaped button?

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.

How do you make a button round in HTML?

Rounded corners HTML Buttons You can make rounded corners button by adding border-radius of 5px to 10px on HTML buttons.

How do you make a button circular in CSS?

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.

How do you round the corners of a button?

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.


1 Answers

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

enter image description here

Geometry in this concept

enter image description here

like image 164
Vijay-Apple-Dev.blogspot.com Avatar answered Nov 04 '22 16:11

Vijay-Apple-Dev.blogspot.com