代码之家  ›  专栏  ›  技术社区  ›  thedonniew

自定义UIImage作为UIBarButtonItem显示像素化/模糊

  •  1
  • thedonniew  · 技术社区  · 10 年前

    我正在使用自定义图像作为条形按钮项。在iPhone屏幕上看起来不错,但在更大的显示器(iPad)上运行时似乎像素化了。

    iPad2:

    iPad2 simulator

    iPhone 6S:

    iPhone 6S simulator

    这是我的代码:

    // Set Custom Image for Bar Button Item
        let button = UIButton(type: .Custom)
        button.setImage(UIImage(named: "Share.png"), forState: UIControlState.Normal)
        button.addTarget(self, action:"shareButtonClicked", forControlEvents: UIControlEvents.TouchDragInside)
        button.frame=CGRectMake(0, 0, 30, 30)
        let barButton = UIBarButtonItem(customView: button)
        self.navigationItem.rightBarButtonItem = barButton
    

    我应该如何设置图像比例?

    1 回复  |  直到 10 年前
        1
  •  2
  •   Victor Engel    10 年前

    iPhone 6s有一个视网膜显示屏。iPad2没有。在比那个版本晚的iPad上试用,它将是一个视网膜显示器,我打赌它不会显示为像素化。

    通过以下方式,您可能能够改善非视网膜显示器上使用的图像 choosing the resampling method 仔细地从更大的图像中选择。