2016-10-11 60 views
0

enter image description here在我的应用程序中,我想在单个UIButton上添加多个图像。Swift将多个图像添加到单个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) 

我想将第二图象作为一个箭头指向下一个页面。 在此先感谢:)

按钮作品的其余部分,但我不知道如何使箭头出现

+0

如果您提供了您拥有的内容和想要获得的内容的屏幕截图,那就太好了。 –

+0

1秒生病只是预览 –

回答

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我对齐按钮上的图像。

+0

请解释你想达到什么以及这个答案如何解决你的问题。否则,它将对未来的访问者没有价值。谢谢。 – xpereta

+0

增加了一个解释是这样清楚还是我需要或添加别的东西? –

相关问题