swiftborderxcode6.1

Setting a Border for TextView (Xcode 6.1)


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.


Solution

  • 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.
        }
    
    
    }