这就是我现在所拥有的:
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)
我希望第二张图片作为指向下一页的箭头。 提前谢谢:)
按钮的其余部分有效,但我不知道如何使箭头显示
答案 0 :(得分:0)
我在这里修复了问题是新代码:
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我对齐按钮上的图像。