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?
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.
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.
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.
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:
Put it inside an UIImageView
let logo = UIImage(named: "logo.png") let imageView = UIImageView(image:logo) self.navigationItem.titleView = imageView
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