Ios UIBarButtonItem图像正在拉伸,即使使用的图像是推荐的20 x 20分

Ios UIBarButtonItem图像正在拉伸,即使使用的图像是推荐的20 x 20分,ios,objective-c,iphone,xcode,Ios,Objective C,Iphone,Xcode,我正在尝试自定义我的导航栏,并且有两个需要显示图标的栏按钮项。我刚刚在故事板中创建了条形按钮项目,并将每个项目的图像设置为图标。图标都是大小正确的PNG(20 x 20磅),但是它们显示的比它们应该显示的大得多,因此它们在导航栏上的两个方向上看起来都很稳定 我在storyboard中做所有的事情,除了我必须在viewDidLoad方法中添加一些代码。我不确定这是否会影响什么,但这里是: //Make the navigation bar transparent [self.navigationC

我正在尝试自定义我的导航栏,并且有两个需要显示图标的栏按钮项。我刚刚在故事板中创建了条形按钮项目,并将每个项目的图像设置为图标。图标都是大小正确的PNG(20 x 20磅),但是它们显示的比它们应该显示的大得多,因此它们在导航栏上的两个方向上看起来都很稳定

我在storyboard中做所有的事情,除了我必须在viewDidLoad方法中添加一些代码。我不确定这是否会影响什么,但这里是:

//Make the navigation bar transparent
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

//Setup navigation bar with Avenir Next Regular font and white title color
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AvenirNext-Regular" size:17], NSFontAttributeName, nil]];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
我是一个编程新手,这是我的第一个问题。我会在图片中说明这个问题,但我需要10个信誉点


提前感谢您的帮助

您必须为不同的设备提供不同分辨率的图像。最简单的方法是使用Xcode中的xcassets文件夹并填写所有模板:正常大小、2x、3x

如果不想使用xcassets,则必须自己命名文件:

image.png
image@2x.png
image@3x.png

Xcode会自动选择正确的大小

这很有效。谢谢你。我甚至都不知道xcassets,所以我现在就来看看!