Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField make text bold?

Tags:

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

like image 775
fuzzygoat Avatar asked Oct 01 '10 16:10

fuzzygoat


People also ask

How do I make my texts bold?

Type the keyboard shortcut: CTRL+B.

How do I make text bold in Swift UI?

Add double asterisks (**) arroud the text/characters to make it bold.


2 Answers

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

like image 169
John Wordsworth Avatar answered Nov 11 '22 15:11

John Wordsworth


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.

like image 35
e.James Avatar answered Nov 11 '22 15:11

e.James