Reputation: 1516
I want to resize a button programatically, but modifying the parameters gives no effect.
btnCancel = [UIButton buttonWithType:102];
[btnCancel setFrame:CGRectMake(22.0f, 7.0f, 40.0f, 40.0f)];
[btnCancel setTitle:@"Anuluj" forState:UIControlStateNormal];
[btnCancel setTintColor:[UIColor redColor]];
[btnCancel addTarget:self action:@selector(cancelTyping) forControlEvents:UIControlEventTouchUpInside];
Any idea why? i can give whatever amount i like to the parameters, but result is the same - width is bounded to text length.
Upvotes: 0
Views: 106
Reputation: 27618
I took your code and tested it in iOS 6.0. This is the final version of what you need to do
Add QuartzCore Library and add this to your header file
#import <QuartzCore/QuartzCore.h>
Now here's your button code with a pic. Play around with width and hight and they will change
UIButton *btnCancel =[UIButton buttonWithType:UIButtonTypeCustom];
[btnCancel setFrame:CGRectMake(22.0f, 7.0f, 80.0f, 80.0f)];
[btnCancel setTitle:@"Anuluj" forState:UIControlStateNormal];
btnCancel.backgroundColor = [UIColor redColor];
btnCancel.layer.borderColor = [UIColor redColor].CGColor;
btnCancel.layer.borderWidth = 0.5f;
btnCancel.layer.cornerRadius = 10.0f;
[btnCancel addTarget:self action:@selector(cancelTyping) forControlEvents:UIControlEventTouchUpInside];
Upvotes: 1
Reputation: 2756
use [UIButton buttonWithType:UIButtonTypeCustom]
with appropriate value, button will resize.
UIButtonTypeCustom = 0,
UIButtonTypeRoundedRect,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd
Upvotes: 0
Reputation: 607
you almost certainly have autolayout turned on. Go into interface builder and turn it off and your code should work
Upvotes: 0
Reputation: 3991
Try to change btnCancel = [UIButton buttonWithType:102];
by btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
Upvotes: 0