How to make a simple rounded button in Storyboard?

后端 未结 13 1826
渐次进展
渐次进展 2021-01-29 19:49

I just started learning iOS development, cannot find how to make simple rounded button. I find resources for old versions. Do I need to set a custom background for a button? In

13条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 20:00

    Try this!!

     override func viewDidLoad() {
       super.viewDidLoad()
    
       var button = UIButton.buttonWithType(.Custom) as UIButton
       button.frame = CGRectMake(160, 100, 200,40)
    
       button.layer.cornerRadius =5.0
       button.layer.borderColor = UIColor.redColor().CGColor
       button.layer.borderWidth = 2.0
    
       button.setImage(UIImage(named:"Placeholder.png"), forState: .Normal)
       button.addTarget(self, action: "OnClickroundButton", forControlEvents: .TouchUpInside)
       button.clipsToBounds = true
    
       view.addSubview(button)
    }
        func OnClickroundButton() {
       NSLog(@"roundButton Method Called");
    }
    

提交回复
热议问题