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.
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;
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