简体   繁体   中英

iOS Image in navigation Item titleview

I want to add an image in my navigation bar. To do this, i wrote that :

        self.navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"logo.png"]];

It's running, but the only problem is the image seems to be blurred. When i look it on photoshop or other software, the image is perfect.

The size of this image is : 120 x 30px.

Someone to help me ? Thx

First of all, please, print self.navigationItem.titleView.frame after your viewDidAppear.

Seems to be, that in some case your titleView is placed with half-pixeled origin.x, or origin.y.

Try to play with:

[self.navigationController.navigationBar setTitleVerticalPositionAdjustment:<#(CGFloat)#> forBarMetrics:<#(UIBarMetrics)#>]

Try to set different values to the first param and observe the result.

You can change the navigation and status bar background only in iOS7. For this, you can use

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourImage.png"] forBarMetrics:UIBarMetricsDefault];

The size should be 320*64 px

and to change the Navigation Bar title

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM