I have this code to add a 26 x 30 .png file into the right view of a UITextField.
//add button to address bar
//UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setImage:[UIImage imageNamed:@"refresh.png"] forState:UIControlStateNormal];
[refreshButton setImage:[UIImage imageNamed:@"refresh.png"] forState:UIControlStateHighlighted];
refreshButton.imageEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0);
[refreshButton addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
addressBar.rightView = refreshButton;
addressBar.rightViewMode = UITextFieldViewModeUnlessEditing;
the button is touchable and calls the method that it should, but the image is not displayed.
any ideas? could it be that the image is too big for the text field? My text field is the standard size that I dragged into from IB, so I don't think that's it, but it's an idea.
the text field is 245 x 31
Have you tried specifying a frame when initializing your UIButton instead of using the class method buttonWithType. I am guessing the textfield cannot determine the size of your button without it.
[[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, height)]
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