I've tried finding the answer to this and every time it's assuming I know way too much. I'm a total beginner. I just created a new, blank application. I dragged the TextView to the storyboard. What do I do next to give it a border?
There is no code other than the default, autogenerated code at this point.
You can do this by choosing the assistant editor. Than control drag a line from the outlet in the code to the textfield. After the textfield is connected, you can add code to make a border in the viewDidLoad function. class ViewController: UIViewController { @IBOutlet var text : UITextField?
Here are the steps: If you let Xcode create a project, go to the ViewController.swift file. Here you can create an outlet.
@IBOutlet var text : UITextField?
Now you can connect the text outlet to the textfield in the storyboard. You can do this by choosing the assistant editor. Than control drag a line from the outlet in the code to the textfield.
After the textfield is connected, you can add code to make a border in the viewDidLoad function.
class ViewController: UIViewController {
@IBOutlet var text : UITextField?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
text!.layer.borderWidth = 1
text!.layer.borderColor = UIColor.redColor().CGColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
In Swift 3 and Xcode 10, tested and working in (swift 5 and code 12)
first, create an outlet of your text view
And In your viewdidload put these two lines
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.textView.layer.borderColor = UIColor.lightGray.cgColor
self.textView.layer.borderWidth = 1
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With