Swift将多个图像添加到单个UIButton

在这里输入图像说明 在我的应用程序中,我想在一个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) 

我想第二个图像作为箭头指向下一页。 提前致谢 :)

button的其余部分工作,但我不知道如何使箭头出现

我在这里解决了这个问题是新的代码:

  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的顶部创build第二个图像。 然后通过起诉imageEdgeInsets我alignmentbutton上的图像。