Thursday, 14 May 2015

Adding Add ons on UITextField

Objective:
                To try and add some interesting things to the UITextfield

What interesting things?

1.Adding a custom fonts;
2.Adjusting the font sizes to fit the width;
3.set an background image to the textfield;
4.setting an logo inside an textfield [left view];
5.Setting maximum character length;

Approach:

1.Import <UITextFieldDelegate and an Instance of UITextField;
2.Create a textField Either by programatically or by Xib or through StoryBoard;



To add a custom Font:




Adjusting the font sizes to fit the width:





Set an background image to the textfield:




when we compile & run the code-the output is :




setting an logo inside an textfield :






Setting maximum character length:

If we have to limit our character length in a textfield,We have to import this delegate method:-

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

and add the following code to the delegate method:














The above method should return true if a planned text substitution should be allowed to happen, false otherwise. The return statement evaluates to true if the new string will be of length 5 or less.





No comments:

Post a Comment