Reputation: 25
I have created a Approver's Remarks TextView in my MainstoryBoard and created an outlet for it in ApproveViewController. I am trying to create a border for my Textview using storyBoard and code
1) So First, I have created a class called BorderTextView1. Below is my code for class BorderTextView1
import UIKit
@IBDesignable
class BorderTextView1: UITextView {
var red = UIColor(red: 100.0, green: 130.0, blue: 230.0, alpha: 1.0)
@IBInspectable var borderColor: UIColor? {
set {
layer.borderColor = red.cgColor
}
get {
guard let color = layer.borderColor else {
return nil
}
return UIColor(cgColor: color)
}
}
@IBInspectable var borderWidth: CGFloat {
set {
layer.borderWidth = 2
}
get {
return layer.borderWidth
}
}
@IBInspectable var cornerRadius: CGFloat {
set {
layer.cornerRadius = 2.0
clipsToBounds = newValue > 0
}
get {
return layer.cornerRadius
}
}
}
2)And then I have set the custom class as "BorderTextView1" for the textview object in storyboard.
3)so when I run the code, I am able to set the border for the textview in the attribute inspector,
But still I am not able to view the border of Approver's Remarks textview in my simulator. Please provide a solution.
I have attached the screenshot for the attribute inspector selection and the custom class setting.
Setting the Custom class of TextView object
Setting the border colour for textview during Runtime
Upvotes: 2
Views: 1768
Reputation: 4075
Below Code, gives following error:
var red = UIColor(red: 100.0, green: 130.0, blue: 230.0, alpha: 1.0)
UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug
Rewrite:
var red = UIColor(red: 100.0/255.0, green: 130.0/255.0, blue: 230.0/255.0, alpha: 1.0)
Output:
Upvotes: 3