简体   繁体   English

将forwardIcon添加到以编程方式创建的UIButton中

[英]Adding forwardIcon into a programmatically created UIButton

I have a UIButton created programmatically and I need to add a forward icon which has to be created using UIBezierPath as shown in the figure below. 我有一个以编程方式创建的UIButton,我需要添加一个向前图标,该图标必须使用UIBezierPath创建,如下图所示。 How do I do that . 我怎么做 。 I am a beginner in iOS and I need help. 我是iOS的初学者,需要帮助。 The end result I want is this 我想要的最终结果是

The code I have is this: 我的代码是这样的:

let forwardButton : UIButton = {
    let fb = UIButton()
    fb.translatesAutoresizingMaskIntoConstraints = false
    fb.backgroundColor = UIColor(red:0.56, green:0.07, blue:1.00, alpha:1.0)
    return fb
}()

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    forwardButton.bounds.size.width
    forwardButton.layer.masksToBounds = true

}

I have code for circular button but I don't know how to draw forward icon using bezierpath inside the circular button. 我有圆形按钮的代码,但我不知道如何在圆形按钮内使用bezierpath向前绘制图标。 any help would be appreciated 任何帮助,将不胜感激

You can add this code : 您可以添加以下代码:

fb.setImage(UIImage(named: "yourImageName.png"), for: .normal)

If you are using xcasset you can use (no need .png): 如果您使用的是xcasset,则可以使用(不需要.png):

if let image = UIImage(named: "Done") {
   fb.setImage(image, for: .normal)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM