【问题标题】:UIImages will not resize based on device sizeUIImages 不会根据设备大小调整大小
【发布时间】:2016-06-17 21:39:42
【问题描述】:

好的,所以我在 UIScrollView 上创建了一个 UIButton,并且我让按钮有一个图像。我的应用程序是通用的,每个设备的按钮大小相同。我希望它根据设备大小更改大小,就像它是具有 3x、2x 和 1x 图像的 SpriteNode 一样。我该怎么做?

    let button = UIButton(type: .Custom)
    let image = UIImage(named:"Buy5Button")
    button.frame = CGRectMake(0, 0, (image?.size.width)!, (image?.size.height)!)
    button.setImage(image, forState: .Normal)
    button.addTarget(self, action: "something", forControlEvents: .TouchUpInside)
    scrollView.addSubview(button)
    self.view?.addSubview(scrollView)

【问题讨论】:

    标签: ios swift uibutton uiimage uikit


    【解决方案1】:

    将按钮框架设置为您想要的任何大小(它将自动适应设备分辨率)。然后最终将图像框架设置为与按钮框架相等。

    在这种情况下,我倾向于设置按钮的背景图像而不是图像,这样做我只需要定义按钮大小并且背景图像会自动缩放...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      相关资源
      最近更新 更多