Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

UINavigationBar customization

I am trying to customize my nav bar and I am writing code in app delegate to achieve that. Here is code.

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"topbar"] forBarMetrics:UIBarMetricsDefault];

However, is there a way I can do similar thing with a image component and repeating that image component?

Like we do to assign Views. Something like this:

UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"iamge_Name"]]; self.tableview.backgroundcolor = color;

2 Answers

Jonathan Baker
Jonathan Baker
2,304 Points

There isn't an easy way to use a pattern image with UINavigationBar without creating your own image using CGContext and the pattern color.

The better approach is to make a resizable image and then setting that as the backgroundImage of the navigation bar.

For example, if you have an image that is say 1px x 44px, you can turn this into a resizable image that will essentially "stretch" to fit the length of the navigation bar.

UIImage *background = [[UIImage imageNamed:@"myResizableImage"] resizableImageWithCapInsets: UIEdgeInsetsZero];

That works. Thank you.

Jonathan Baker
Jonathan Baker
2,304 Points

Glad I could help! If you wouldn't mind, please mark my answer as the correct one so the question appears as answered in the list. Good luck!