Skip to main content

Posts

Showing posts from 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

UITableView basic tutorial

In this tutorial we will create a table view with some dummy data, we will use disclosure indicator, change background color of cell, handle user selection, change separator color etc. There many tutorials which provides in depth information on UITableViews thus I will not touched that and instead targeted the practical How Tos. Create a new single view project and add a UITableView to the initial view controller which has been added to the storyboard automatically. In order to use UITableView in your viewcontroller you need to adapt to UITableViewDataSource and UITableViewDelegate.  UITableViewDelegate provides us with methods which let us handle user selection events, define row height, modifying view and much more. UITableViewDataSource provides data to UITableView to construct the view (to render content). Create table view cells, define the number of sections, number of rows in sections and much more. Adapt to required protocols @interface AYVie