Question

I have an image/banner that I want to use as the title for a navigation bar. The image's resolution is 720x227 px. I threw the image into a UIButton who's frame I set as 79x25:

UIButton* titleImage = [[UIButton alloc] initWithFrame:CGRectMake(0,0,79,25)];
[titleImage setBackgroundImage:[UIImage imageNamed:@"title.png"] forState:UIControlStateNormal];
[titleImage setUserInteractionEnabled:NO];
self.navigationItem.titleView = titleImage;

The height adjusts perfectly. The width however is stuck around 250px and refuses to adjust no matter what number I put in, as you can see below. Can anyone see why? Let me know what other pieces of code you need to see.

enter image description here

edit: I've also tried to cut out the UIButton and simply threw it into an imageview like so:

UIImageView* titleImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 25)];
[titleImage setImage:[UIImage imageNamed:@"title.png"]];
self.navigationItem.titleView = titleImage;

However, the problem persists.

Was it helpful?

Solution

I recommend you resize the image so it will fit the navigation bar, there's no reason to load such a large image into memory when only a scaled down image is being shown anyway.

Your app will load a little faster to boot.

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