Button Border with Transparent Background in Swift

前端 未结 4 2095
灰色年华
灰色年华 2021-02-04 05:37

How can I make a UIButton border to look alike in the below image (the \"Getting Started\") button with a transparent background?

How should I achieve this

4条回答
  •  被撕碎了的回忆
    2021-02-04 05:56

    Swift 5

    Similar to @rakeshbs, but in Swift 5:

        let borderAlpha : CGFloat = 0.7
        let cornerRadius : CGFloat = 5.0
    
        self.frame = CGRect(x: 100, y: 100, width: 200, height: 40)
        self.setTitle("Login", for: UIControl.State.normal)
        self.setTitleColor(UIColor.white, for: UIControl.State.normal)
        self.backgroundColor = UIColor.clear
        self.layer.borderWidth = 1.0
        self.layer.borderColor = UIColor(white: 1.0, alpha: borderAlpha).cgColor
        self.layer.cornerRadius = cornerRadius
    

提交回复
热议问题