Sunday, June 2, 2013

UITextField font example in Objective C (iOS).


UITextField font

The font of the text.

@property(nonatomic, retain) UIFont *font

Discussion of [UITextField font]
This property applies to the entire text of the text field. It also applies to the placeholder text. The default font is a 12-point Helvetica plain font.

If you are using styled text in iOS 6 or later, assigning a new value to this property causes the font to be applied to the entirety of the string in the attributedText property. If you want to apply the font to only a portion of the text, create a new attributed string with the desired style information and associate it with the text field.

UITextField font example.
- (void)viewDidLoad
{  
    CGRect noteTitleTextFrame  = CGRectMake(self.view.bounds.origin.x,
                                            self.view.bounds.origin.y+10,
                                            self.view.bounds.size.width,
                                            44);
    RLTextField *textField = [[RLTextField alloc] initWithFrame:noteTitleTextFrame];
    self.nameTextField = textField; [textField release];
    self.nameTextField.delegate = self;
    self.nameTextField.borderStyle = UITextBorderStyleNone;   
    self.nameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    self.nameTextField.font = [UIFont fontWithName:@"Courier New" size:21];
    [self.view addSubview:self.nameTextField];
}

End of UITextField font example article.