【发布时间】:2016-04-01 09:59:03
【问题描述】:
我已将transparent image 设置为background,用于我正在使用的UIButton。它看起来很完美,但问题是transparent image 相当小,因此用户在第一次尝试时很难正确单击它。
这是我的代码:
optionsButton.setBackgroundImage(UIImage(named: "CalendarEventArrowIcon"), forState: UIControlState.Normal)
optionsButton.addTarget(self, action: "optionsButtonPressed", forControlEvents: UIControlEvents.TouchDown)
有没有一种方法可以获取我正在使用的当前图像,并将其放置在具有更大框架的 UIImage 中,然后在Swift 中将其作为按钮programmatically 的背景图像?
通过这样做,用户可以更轻松地点击按钮,因为背景图片会占据更大的区域。
或者是我真正做这样的事情以返回 Photoshop 并使我正在使用的 background image 更大并且不再有 transparent background 的唯一方法?
【问题讨论】:
-
hm ...我建议您再次执行 Photoshop 工作以使图片足够大。
-
最简单的方法是放大图片,或者将按钮嵌入到一个清晰的 UIView 中,并在其中添加一个点击手势识别器来触发 optionsButtonPressed 操作。
标签: ios swift uibutton swift2 ios9