How to set the border of UITextView to same as border color of UITextField

前端 未结 8 2031
遇见更好的自我
遇见更好的自我 2020-12-24 10:37

By default UITextField has a light gray color as its border color. I want to set my UITextView to have the same border color as the UITextField.

I tried:

<         


        
8条回答
  •  执笔经年
    2020-12-24 11:17

    swift 4.x/ios11.

    I did another measure in PSD using simulator. I can confirm radius is 0.5 and color is 0.8, as 205/255 = 0.8 (or "cdcdcd" in HEX, as PSD suggests, BUT width must be 0.5. (I attached a PSD where You can compare radius of edit field (UITExtField) AND radius applied to a UITextView.

    So its correct:

        let borderGray = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1)
        self.TxtV.layer.borderColor = borderGray.cgColor
        self.TxtV.layer.borderWidth = 0.5
        self.TxtV.layer.cornerRadius = 5
    

    Note: I tried to get color from a TextField already on View, but I got:

    if let borderGray = self.cellPhoneTxt.layer.borderColor{ let BG = UIColor(cgColor: borderGray)

        print(BG)
        var red: CGFloat = 0
        var green: CGFloat = 0
        var blue: CGFloat = 0
        var alpha: CGFloat = 0
        BG.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
        print(red, green, blue, alpha)
    
    }
    

    but I got in console:

    kCGColorSpaceModelRGB 0 0 0 1

    0.0 0.0 0.0 1.0

    so it seems Apple is using full black AND some Alpha.

提交回复
热议问题