Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frame of UIButtonTypeRoundedRect

Tags:

iphone

For UIButton i was using first UIButtonTypeCustom now i want to change it to RoundedRect but when i change UIButtonTypeCustom to UIButtonTypeRoundedRect it shows RoundedRect in white instead of color specified for it and plus it shows edges of rect buttonframe in back of roundedrect button. So i want to know how to fix this thing.

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 30);

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor colorWithHue:1.0/12 saturation:2.0/3 brightness:4.0/10 alpha:1.0];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setLeftBarButtonItem:button animated:YES];

Thanks for help.

like image 263
user1120133 Avatar asked Jan 23 '26 06:01

user1120133


1 Answers

Mmm... I afraid it is not possible to change the backgroundColor of your UIButton if it is UIButtonTypeRoundedRect.

My suggestion is to create a UIButtonTypeCustom and change its layer to mimic a UIButtonTypeRoundedRect.

Try this code:

#import <QuartzCore/QuartzCore.h>

[myButton.layer setMasksToBounds:YES];
[myButton.layer setCornerRadius:10.0f];
[myButton.layer setBackgroundColor:[UIColor whiteColor].CGColor;
like image 128
Giuseppe Garassino Avatar answered Jan 25 '26 19:01

Giuseppe Garassino