Question

I have an iOS app with a UIToolbar with several buttons on it. One of them I change the image programatically based on the date as follows:

[_button setImage: [UIImage imageNamed: @"blah"]];

_button is an IBOutlet.

On the iPhone it works just fine but every time I run the app on the iPad I get the glitch shown in the image bellow. Any idea what might be causing this?

http://imagebin.org/306704

Was it helpful?

Solution 2

Try This

UIButton *btton = [UIButton buttonWithType:UIButtonTypeCustom];
[btton setFrame:CGRectMake(0, 0, 20, 20)];
[btton addTarget:self action:@selector(actionMenu:) forControlEvents:UIControlEventTouchUpInside];
 [btton setImage:[UIImage imageNamed:@“blah.png"] forState:UIControlStateNormal];

UIBarButtonItem * barbutton = [[UIBarButtonItem alloc] initWithCustomView:btton];

OTHER TIPS

Let's try:

UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setFrame: CGRectMake(0, 0, closeButtonFontSize.width, closeButtonFontSize.height)];
[closeButton.titleLabel setFont: font];
[closeButton setTitle: closeStr forState: UIControlStateNormal];
[closeButton setTitleColor: hoverColor forState: UIControlStateHighlighted];
[closeButton addTarget:self action:@selector(closePressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *closeBarButton = [[UIBarButtonItem alloc] initWithCustomView:closeButton];
//set this bar button to your toolbar

SetImage directly not working for button, we set image and state for button like this

[_button setImage:[UIImage imageNamed: @"blah"] forState:UIControlStateNormal];

UIBarButtonItem with image

UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action)];

else you customize your barbuttonitem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top