目标 C:如何保持导航按钮和选项卡栏中的图像分辨率/质量
我试图通过以下代码将图像放置到导航项的右侧按钮
//Add image to right bar button in navigation bar
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(getData)];
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];
图像我的尺寸为 52 X 52 像素。 如果我只是将图像添加到按钮而不更改大小,我将得到不成比例的显示,如下所示
但是,如果我在添加到按钮之前尝试缩小图像(18 X 18 像素),则图像在 iPhone 视网膜显示屏上看起来会很模糊
iPhone 视网膜显示屏的标签栏也会发生这种情况。
有没有办法在按钮或选项卡中使用大图像而不会出现不成比例的显示?或者有没有办法保持图像的分辨率?
I am trying to put an image to the navigation item's right button via the following code
//Add image to right bar button in navigation bar
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(getData)];
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];
The image I has a dimension of 52 X 52 pixels.
If I just add the image into the button without changing the size, I will get a unproportionate display as seen below
However, if I try to shrink the image before adding to the button (18 X 18 pixels), the image will look blurry on the iPhone retina display
This is also happening for the tab bars for the iPhone retina display.
Is there any way to use a large image in the button or tab without getting a disproportionate display? Or is there a way to maintain the resolution of the image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要创建两个图形资源,一个为正常大小,另一个为视网膜加倍,并在文件名中添加@2x。您可以阅读更多信息:
https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreensInViews/SupportingHiResScreensInViews.html#//apple_ref/doc/uid/TP40010156-CH15-SW1
You need to create two graphic assets, one in normal size other doubled for retina with @2x added to filename. You can read more at:
https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreensInViews/SupportingHiResScreensInViews.html#//apple_ref/doc/uid/TP40010156-CH15-SW1
在界面生成器中查看图像的边缘插入。您可以调整左右值来调整 UIButton 中更大图像的大小。
UIbutton 的等效属性是
[uiButton setImageEdgeInsets:<#(UIEdgeInsets)#>]
Check out the Edge Insets for image in the interface builder. You can adjust the left right values to resize a bigger image in a UIButton.
Equivalent property of UIbutton is
[uiButton setImageEdgeInsets:<#(UIEdgeInsets)#>]