Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round UIButton

Tags:

ios

uibutton

I want to know whether drawing a round UIButton(not rounded rect) is possible.

When I add a round image in a UIButton of type custom, then it looks like a round button. But at the moment the button is clicked the boundary of the button becomes visible, so that it looks like a square button, then again when the click ends it looks like a round button.
I want the button to look like a round button even at the moment the click happens. is this possible?

like image 274
saikamesh Avatar asked Dec 03 '22 15:12

saikamesh


1 Answers

Tested Code:

.h

    -(void)vijayWithApple; 

.m

   -(void)vijayWithApple{

            NSLog(@"vijayWithApple Called");
   }


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setImage:[UIImage imageNamed:@"Micky.png"] forState:UIControlStateNormal];

[button addTarget:self action:@selector(vijayWithApple) forControlEvents:UIControlEventTouchUpInside];

[button setTitle:@"Show View" forState:UIControlStateNormal];

button.frame = CGRectMake(135.0, 180.0, 40.0, 40.0);//width and height should be same value

button.clipsToBounds = YES;

button.layer.cornerRadius = 20;//half of the width

button.layer.borderColor=[UIColor redColor].CGColor;

button.layer.borderWidth=2.0f;

[self.view addSubview:button];

Result

enter image description here

like image 149
Vijay-Apple-Dev.blogspot.com Avatar answered Jan 15 '23 20:01

Vijay-Apple-Dev.blogspot.com