Small ‘feature’ in iOS4

Posted by admin on Saturday Jul 3, 2010 Under App Development

In my upcoming app ‘FlirtSMS’ I draw a UIButton in the right hand side of a UITextField. This was working fine on 3.1.3 but now in iOS4 it disappears. Thanks to Sylver over on the iPhoneDevSDKForums as my existing code;

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateHighlighted];
button.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);

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

addContact.rightView = button;
addContact.rightViewMode = UITextFieldViewModeAlways;

Simply needed the following line added;

button.bounds = CGRectMake(0, 0, 35, 32);

Because the bounds of the button are set to zero by default.

Leave a Reply