xcode 为什么 UIBarButtonItem 图像总是模糊/模糊/像素化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25853680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:33:35  来源:igfitidea点击:

Why is UIBarButtonItem image always fuzzy/blurry/pixelated

xcodeswiftuibuttonuibarbuttonitemuinavigationitem

提问by Mate Hegedus

Here is my current code:

这是我当前的代码:

var reply = UIBarButtonItem(image: UIImage(named: "reply"), style: UIBarButtonItemStyle.Plain, target: self, action: Selector("reply:"))
self.navigationItem.rightBarButtonItem = reply

imgThe button in the top right corner is always fuzzy. This is a screenshot from an iPhone4s device so it is not a retina-related issue.

图片右上角的按钮总是模糊的。这是 iPhone4s 设备的屏幕截图,因此它不是与视网膜相关的问题。

I have tried different image sizes ranging from 30x30 to 512x512 and adding the image using customView. These methods have not fixed the issue.

我尝试了从 30x30 到 512x512 的不同图像大小,并使用 customView 添加图像。这些方法都没有解决问题。

Thanks in advance.

提前致谢。

回答by Mate Hegedus

I have solved it using this method:

我已经使用这种方法解决了它:

var replyBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
replyBtn.setImage(UIImage(named: "reply"), forState: UIControlState.Normal)
replyBtn.addTarget(self.navigationController, action: Selector("reply:"), forControlEvents:  UIControlEvents.TouchUpInside)
var item = UIBarButtonItem(customView: replyBtn)
self.navigationItem.rightBarButtonItem = item

It displays a very crisp button using the exact same image.

它使用完全相同的图像显示一个非常清晰的按钮。

回答by LS_

From IOS human interface guide the icon should be 22x22 Take a look at the documentation here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/BarIcons.html

从 IOS 人机界面指南中,图标应该是 22x22 看看这里的文档:https: //developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/BarIcons.html