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
Type the keyboard shortcut: CTRL+B.
Add double asterisks (**) arroud the text/characters to make it bold.
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: https://www.cocoanetics.com/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; https://developer.apple.com/documentation/uikit/uifont
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With