views:

67

answers:

3

Quick question, does anyone know how to programatically make the text in the textField bold or italic?

   @property(nonatomic, retain) IBOutlet UITextField *textField_TOP_01;

   [textField_TOP_01 setTextColor:[UIColor redColor]];
   [textField_TOP_01 setText:@"This text is bold"];

Much appreciated

Gary

+1  A: 

Attributes like bold and italic can be set by using the appropriate font. See this answer for more details.

UIFont * font = [UIFont fontWithName:@"Helvetica-Bold"
                                size:[UIFont systemFontSize]];
[textField setFont:font];

Alternatively, if you are just looking to create bold and italic versions of the standard iPhone system font, you can use the boldSystemFontOfSize: or italicSystemFontOfSize: methods.

e.James
A: 

There is a property called UIFont

@property(nonatomic, retain) UIFont *font

For creating a UIFont with a bold, I think you can use:

+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize

UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:[UIFont systemFontSize]];

vodkhang
+6  A: 

You can use the following methods to get a bold or italic system font;

UIFont* boldFont = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
UIFont* italicFont = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];

Then simply set the font that the text field uses;

[textField_TOP_01 setFont:boldFont];

If you want to see more about fonts with the iPhone, you can see a nice screen shot of all of the available fonts here: http://www.drobnik.com/touch/2010/02/understanding-uifont/ or you can read about the class which shows you how you can also pull out the 'buttonFontSize' and 'labelFontSize' etc here; http://developer.apple.com/library/ios/#documentation/uikit/reference/UIFont_Class/Reference/Reference.html

John Wordsworth