【发布时间】: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