italic, bold and underlined font on iPhone - iphone

How do you set a font to be both bold and italic. There is a boldSystemFontOfSize and italicSystemFoneOfSize, but I can't see the way to set a font to be both italic and bold.
As a second question, is there a way to set an underline on a font, or do you simply draw a line under text.

You have to actually ask for the bold, italic version of a font. For example:
UIFont *myFont = [UIFont fontWithName:#"Helvetica-BoldOblique" size:[UIFont systemFontSize]];
To get a list of everything available on the iPhone, put this little snippet in your applicationDidFinishLaunching: delegate method and look at the log output:
for (NSString *family in [UIFont familyNames]) {
NSLog(#"%#", [UIFont fontNamesForFamilyName:family]);
}
Note: Some font names say "oblique" - this is the same as italic.
I can't see a built-in way of doing underlines - you may have to draw the line yourself.

I recently wrote a blog post about the restrictions of the UIFont API and how to solve it.
You can see it at http://eclipsesource.com/blogs/2012/07/26/uifont-from-a-css-definition/
With the code I provide there, you can get your desired system UIFont as easy as:
UIFont *myFont = [FontResolver fontWithDescription:#"font-family: sans-serif; font-weight: bold; font-style: italic;"];

Related

How to get Font style from UILabel?

How to get the font style of UILabel? Whether it is Bold or italic ?
You will need to inspect the font name.
myLabel.font.fontName
http://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006891-CH4-SW16
Try this one:
NSAttributedString *string=yourLabel.attributedText;
if ([[textFieldFontName rangeOfString:string] length] > 0){
NSLog(#"Bold");
}
if ([[textFieldFontName rangeOfString:string] length] > 0){
NSLog(#"Italic");
}
*Note if your string contains both then, this may not work
Select your label in the interface builder (xib or storyboard) and go to the Attributes Inspector. There click on the "T" by font and then set font to Custom.
Now you can change the font, size etc.
UILabel *myLabel;
myLabel.font = [UIFont fontWithName:#"fontName" size:16.0];//set font according your choice
myLabel.font = [UIFont boldSystemFontOfSize:16.0];//bold font
myLabel.font = [UIFont systemFontOfSize:16.0];//system font
Hope it's helpful for you....

UILabel font : bold and italic [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I set bold and italic on UILabel of iPhone/iPad?
I am trying to make UILabel font bold and italic both using system font, but I cant use these both style at a time. so is it possible to make font bold and italic using system font? here is my code,
lblTitle.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
or
lblTitle.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
I want my font Bold and Italic both.
Can anyone help me?
Thank you in advance.
try this code...
UIFont *yourFont = [UIFont fontWithName:#"Helvetica-BoldOblique"
size:[UIFont systemFontSize]];
lblTitle.font = yourFont;
you can use also another fontName for BoldItalik like.
Optima-BoldItalic,TimesNewRomanPS-BoldItalicMT,Baskerville-BoldItalic,HelveticaNeue-BoldItalic,etc...
There are several font that contains Bod+Italic in themselves you can use those fonts...
One frequently for an example is
lblTitle.font = [UIFont fontWithName:#"Arial-BoldItalicMT" size:16.0f];
others are :
- TrebuchetMS-Bold
- Helvetica-BoldOblique
- This link will help you.

iOS - How to set textfield hint to italic (with regular actual text)?

Is there any easy way to set a text field's hint to italic, while keeping the actual text non-italicized? The image below shows what I'm trying to accomplish, but doesn't actually work, as text typed into the first text field is still italicized.
If there's no easy way to do this, I'm thinking that I'll have to implement methods on each of the text fields to check the length of the text, and if zero apply the italic font. This would work, right? Is there a better way?
Try this:
UIFont* italicFont = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[yourTextField setValue:italicFont forKeyPath:#"_placeholderLabel.font"];
EDIT:
Ok, here is another (legal) way to do it:
1.Subclass UITextField and override drawPlaceholderInRect::
TextFieldSubclass.h:
#interface TextFieldSubclass : UITextField
#end
TextFieldSubclass.m:
- (void) drawPlaceholderInRect:(CGRect)rect
{
[[UIColor lightGrayColor] setFill];
UIFont* italicFont = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[[self placeholder] drawInRect:rect withFont:italicFont];
}
2.Change your UITextField class and set it to TextFieldSubclass:
And that's it. Enjoy.

Change font name AND weight in UILabel (iPhone SDK)

Maybe I'm looking at the wrong place, however how do I set an UILabel's font and AND its weight?
Looking at the documentation, there seems to be only methods to create an UIFont with a given font name and size, like
[UIFont fontWithName:#"Helvetica" size:22])
OR create a bold font, with
[UIFont boldSystemFontOfSize:22]
How can I use these both together?
The documentation for fontWithName:size: states, "...name incorporates both the font family and the specific style information for the font."
So you probably want:
[UIFont fontWithName:#"Helvetica-Bold" size:22];
fontNamesForFamilyName: is handy for getting a list of available fonts for a given family.
For example:
NSArray* fontNames = [UIFont fontNamesForFamilyName:#"Helvetica"];
for( NSString* aFontName in fontNames ) {
NSLog( #"Font name: %#", aFontName );
}
...which outputs:
Font name: Helvetica-BoldOblique
Font name: Helvetica
Font name: Helvetica-Oblique
Font name: Helvetica-Bold

UIFont crash problem

When i use this line
[UIFont fontWithName:#"Arial" size:16] its work fine,but
[UIFont fontWithName:#"Arial Black" size:16] it crashes my app.....
In xib design there is the font name of Arial Black is available.But when i set using [UIFont fontWithName:#"Arial Black" size:16] this it crashes my app.. How can i set this font name to uilabel...
Can any one help me?
Check the return value of +[UIFont fontWithName:size:]. My guess is that "Arial Black" is not being found, and a nil font is being returned. Setting a UILabel's font to nil will crash.
To add - using +familyNames and +fontNamesForFamilyName methods in UIFont you can list all fonts available.
You need Arial-BoldMT
[UIFont fontWithName:#"Arial-BoldMT" size:16];
See here