Skip to main content

Posts

Showing posts from July, 2013

Create custom UITextFields and UITextViews with underline

Download In a recent iOS project I needed to create custom UITextView and UITextField. The look and feel had to be same as the Notes app, i.e. the text view and text field both should have horizontal lines as are present in a note. How to create a custom UIView To create a custom UIView we need to inherit from UIView class. We then need to override drawRect method. Override only if you need to change the way view is drawn as this is a performance intensive operation. Custom UITextField In order to create custom UITextField I inherited my class from UITextField. I need to draw a bottom border for this I need override drawRect method. //Get the current drawing context CGContextRef context = UIGraphicsGetCurrentContext(); //Set the line color and width CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); CGContextSetLineWidth(context, 0.5f); //Start a new Path CGContextBeginPath(context); // offset lines up - we are a