我想在导航栏中添加图像。为此,我写道:
self.navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"logo.png"]];
它正在运行,但唯一的问题是图像似乎模糊了。当我在 Photoshop 或其他软件上查看时,图像是完美的。
此图像的大小为:120 x 30 像素。
有人帮我吗?谢谢
我想在导航栏中添加图像。为此,我写道:
self.navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"logo.png"]];
它正在运行,但唯一的问题是图像似乎模糊了。当我在 Photoshop 或其他软件上查看时,图像是完美的。
此图像的大小为:120 x 30 像素。
有人帮我吗?谢谢
首先,请在 viewDidAppear 之后打印 self.navigationItem.titleView.frame。
似乎是,在某些情况下,您的 titleView 与半像素 origin.x 或 origin.y 一起放置。
尝试玩:
[self.navigationController.navigationBar setTitleVerticalPositionAdjustment:<#(CGFloat)#> forBarMetrics:<#(UIBarMetrics)#>]
尝试为第一个参数设置不同的值并观察结果。
您只能在 iOS7 中更改导航和状态栏背景。为此,您可以使用
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourImage.png"] forBarMetrics:UIBarMetricsDefault];
大小应为320*64 像素
并更改导航栏标题
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];