Sunday, June 2, 2013

UITextField leftViewMode example in Objective C (iOS).


UITextField leftViewMode

Controls when the left overlay view appears in the text field.

@property(nonatomic) UITextFieldViewMode leftViewMode

Discussion of [UITextField leftViewMode]
The default value for this property is UITextFieldViewModeNever.

UITextField leftViewMode example.
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;

Example of [UITextField leftViewMode].
CGFloat leftInset = 5.0f;
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, leftInset, self.bounds.size.height)];
self.leftView = leftView;
self.leftViewMode = UITextFieldViewModeAlways;
[leftView release];

UITextField leftViewMode example.
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
      textField.leftView = paddingView;
      textField.leftViewMode = UITextFieldViewModeAlways;

      and you can add UIImageView on this paddingView for your star.png
       UIImageView *img=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star.png"]];
    img.frame=CGRectMake(0, 0,5, 20);
    [paddingView adsubview:img];

End of UITextField leftViewMode example article.