在我的应用程序中,我想在单个 UIButton
上添加多个图像。
这就是我现在拥有的:
NextButton = UIButton(frame: CGRect(x: width*0, y: height*0.55, width: width*0.95, height: height*0.05))
NextButton.addTarget(self, action: #selector(OnNextPressed), for: .touchUpInside)
NextButton.isExclusiveTouch = true
NextButton.setTitle("ButtonText", for: UIControlState())
NextButton.setTitleColor(UIColor(red:0, green:0, blue:0, alpha:1.0), for: UIControlState())
NextButton.setBackgroundImage(UIImage(named: "ButtonOutline"), for: .normal)
view.addSubview(NextButton)
我想要第二张图像作为指向下一页的箭头。 预先感谢:)
按钮的其余部分可以工作,但我不知道如何使箭头出现
最佳答案
我解决了这里的问题是新代码:
let screenSize: CGRect = UIScreen.main.bounds
let width = screenSize.width
let height = screenSize.height
NextButton = UIButton(frame: CGRect(x: width*0, y: height*0.55, width: width*0.95, height: height*0.05))
NextButton.addTarget(self, action: #selector(OnNextPressed), for: .touchUpInside)
NextButton.isExclusiveTouch = true
NextButton.setTitle("ButtonText", for: UIControlState())
NextButton.setTitleColor(UIColor(red:0, green:0, blue:0, alpha:1.0), for: UIControlState())
NextButton.setBackgroundImage(UIImage(named: "ButtonOutline"), for: .normal)
NextButton.setImage(UIImage(named: "arrow_next"), for: UIControlState())
NextButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, width*0.7)
view.addSubview(NextButton)
通过简单地将setImage添加到代码中,我可以在BackgroundImage之上创建第二个图像。然后通过起诉 imageEdgeInsets 我对齐了按钮上的图像。
关于ios - 快速将多个图像添加到单个 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978780/