0

I am using swift 2.0. I have one uitext field for username. Now I also placed the placeholder for that. But when I start typing, the value starts from very corner of that textfield. I need to start slightly before form the corner point for uitext field. Here is my image, this only I need to change.

enter image description here

When I enter any value its starting from very corner. I need to start slightly after that corner point (in swift).

import UIKit


class CustomTextField: UITextField {

    required init?(coder aDecoder: NSCoder){
        super.init(coder: aDecoder)
    }

    override func textRectForBounds(bounds: CGRect) -> CGRect {
        return CGRectMake(bounds.origin.x + 10, bounds.origin.y + 8, bounds.size.width - 20, bounds.size.height - 16);
    }

    override func editingRectForBounds(bounds: CGRect) -> CGRect {
        return self.textRectForBounds(bounds);
    }
}

class ViewController: UIViewController {


    @IBOutlet weak var FirstFiels: UITextField!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
halfer
  • 19,824
  • 17
  • 99
  • 186
user5513630
  • 1,709
  • 8
  • 24
  • 48
  • 2
    Possible duplicate of [Text inset for UITextField?](http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield) – Peba Mar 02 '16 at 17:55
  • => You can use Inset of UITextFiled one of the Post below:- http://stackoverflow.com/questions/3727068/set-padding-for-uitextfield-with-uitextborderstylenone – Akash Mar 02 '16 at 17:58
  • i tried in swift , but it doesn't work, see my updated post – user5513630 Mar 02 '16 at 18:00
  • Make sure you've actually specified `CustomTextField` as the class of the text field in your storyboard. – David Berry Mar 02 '16 at 18:12

0 Answers0