【发布时间】:2019-01-30 15:03:51
【问题描述】:
我正在尝试在我的应用中使用自定义图像作为按钮。如何为图像添加操作?
这适用于 iOS 应用程序,我不想将默认文本按钮用作按钮。我已经尝试控制+拖动图像到 ViewController 但没有“操作”选项。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let designChoice = designPrac.randomElement()
let forChoice = forWhatPrac.randomElement()
let helpChoice = toHelpPrac.randomElement()
designLabel.text = designChoice
forLabel.text = forChoice
helpLabel.text = helpChoice
}
这是我在应用启动时必须运行的代码,但我找不到在单击图像按钮时让它工作的方法。
【问题讨论】:
-
什么图片?您发布的代码似乎与您的问题无关?为什么不在你的图片中使用
UIButton? -
您是否尝试过在图像上制作相同大小的 UIButton 并仅删除“按钮”文本?你试过在 UIImageView 上点击手势吗?
-
我不确定您的图像“使用 UIButton”是什么意思。我是 Swift 的新手,对我的无知感到抱歉。我知道如何向情节提要添加按钮,但不知道如何使其成为我在 Assets.xcassets 中的图像。如何使用点击手势?
-
@bluewizard3 一个普通的 UIButton 可以有一个图像而不是一个标题。
-
stackoverflow.com/questions/27880607/… -> 在imageview上添加点击手势并处理imageview的动作,我们也可以使用UIView的所有子视图。