Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar with UIImage for title

I want to customize my app's look by using a logo image as the navigation bar's title, instead of plain text. When I use this code

let logo = UIImage(named: "logo.png") self.navigationItem.titleView = logo; 

I get the error "UIImage is not convertible to UIView". How can I do this correctly?

like image 695
Darx Avatar asked Jul 17 '14 12:07

Darx


People also ask

How do I customize the right side of the navigation bar?

The right side of the navigation bar options for customization include applying a custom UIView or using a UIBarButtonItem. The sample demonstrates placing three kinds of UIBarButtonItems on the right side of the navigation bar: a button with a title, a button with an image, and a button with a UISegmentedControl.

How do I set the navigation bar as the title view?

Another option is configuring the navigation bar to use a UIView as the title, using UISegmentedControl as the center custom title view. This sample shows how to set a segmented control as the title view: The navigation bar can also include a prompt or single line of text at the top.

What is a uinavigationbar object?

A UINavigationBar object is a bar, typically displayed at the top of the window, containing buttons for navigating within a hierarchy of screens. The primary components are a left (back) button, a center title, and an optional right button.

How do I set the uinavigationbar’s prompt?

Here’s how to set the navigation item’s prompt: Apply a custom background to a UINavigationBar by adding a bar tint color or background image. The sample sets the background image of a navigation bar like this:


1 Answers

Put it inside an UIImageView

let logo = UIImage(named: "logo.png") let imageView = UIImageView(image:logo) self.navigationItem.titleView = imageView 
like image 88
Jack Avatar answered Oct 17 '22 01:10

Jack