iOS UISegmentedControl opens sans font not applying? - ios

I try to apply opensans-regular font to segmented control title. But it is behaving Abnormal. Can't we apply opensans font to UISegmentedControl?
Here is my code
hmSegmentControl.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName : [UIFont fontWithName:#"OpenSans-Regular" size:13]};
hmSegmentControl.selectedTitleTextAttributes = #{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName : [UIFont fontWithName:#"OpenSans-Regular" size:13]};

Issue got fixed. For OpenSans-Regular font, we have to give font name as #"OpenSans" But not #"OpenSans-Regular".

Related

iOS : Mistake with setFont

I'm trying to use setFont on a label, but it seems it doesn't work on iOS > = 8.
I wrote :
UIFont *font = [UIFont fontWithName:#"HelveticaNeue-Light" size:12];
[self->myLabel setFont:font];
Any ideas ?
EDIT : The problem isn't on the font, but on the SIZE. The label stay on the "default" size wrote in the storyboard.
It's because there is no font family with name #"HelveticaNeue-Light" hence size:12 will also not work
And also make sure adjustsFontSizeToFitWidth is disabled with
label.adjustsFontSizeToFitWidth = NO
You can get the available fonts in attribute inspector of Interface Builder

How to use different font name in UITableViewCell UILabel

I want to use different Font name in a UILable in UITableViewCell. I try with a lot of examples like:
Cell.cellSectionLabel.text = [self.textsInTableSection objectAtIndex:0];
Cell.cellSectionImageView.image = [UIImage imageNamed:[self.imagesInTableSection objectAtIndex:0]];
Cell.cellSectionLabel.textColor = [UIColor colorWithRed:59.0f/255.0f green:56.0f/255.0f blue:62.0f/255.0f alpha:1.0f];
[Cell.cellSectionLabel setFont:[UIFont fontWithName:#"Helvetica" size:16]];
Cell.cellSectionLabel.font = [UIFont systemFontOfSize:16];
in cellForRowAtIndexPath
It is not working. The Font name actually read the default Font of my device. Because if I use some different Font name here [Cell.cellSectionLabel setFont:[UIFont fontWithName:#"Baskerville" size:16]];, it doesn't change any thing. It remain the same. How can I use different font name in this case?
Thanks a lot in advance.
You are setting it back to the system font. Delete this line:
Cell.cellSectionLabel.font = [UIFont systemFontOfSize:16];
Please remove the last line of your code and try again.
Cell.cellSectionLabel.font = [UIFont systemFontOfSize:16];
According to your code you are setting font to Helvetica 16
& again changing it back to System font

How to set font name of UILabel as HelveticaNeue Thin in iOS?

I am creating UILabel, for the label i can set the font name as HelveticaNeue Regular, Light, UltraLight etc, But i unable to set the font name as HelveticaNeue Thin, it is not working as expected. I did like,
label.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:16];
Also i have searched on Google didnt got any solution. How to fix this issue? Thanks.
This font is bundled with iOS 7, so if you're targeting iOS 7 and above your
label.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:16.0f];
will work.
However if you are targeting iOS 6.1 and below you'll need to embed the font
Updated answer to support swift
let font = UIFont(name: "HelveticaNeue-Thin", size: 16.0)!
UIFontDescriptor *helveticaNeueFamily =
[UIFontDescriptor fontDescriptorWithFontAttributes:
#{ UIFontDescriptorFamilyAttribute: #"Helvetica Neue" }];
NSArray *matches =
[helveticaNeueFamily matchingFontDescriptorsWithMandatoryKeys: nil];
The matchingFontDescriptorsWithMandatoryKeys: method as shown returns an array of font descriptors for all the Helvetica Neue fonts on the system, such as HelveticaNeue, HelveticaNeue-Medium, HelveticaNeue-Light, HelveticaNeue-Thin, and so on.
You can modify the fonts returned by preferredFontForTextStyle: by applying symbolic traits, such as bold, italic, expanded, and condensed. You can use font descriptors to modify particular traits, as shown in Listing 9-2.
referenced by apple
or
this font you can't apply directly.
so you can customize your font
How to use custom fonts in iPhone SDK?
This has worked for me. Write this code below your label declarations.
It sets all the UILabel under a function with same font.
[[UILabel appearance]setFont:[UIFont fontWithName:#"HelveticaNeue-Thin" size:32.0f]];
To set font to particular UILabel use this code :
[labelName setFont:[UIFont fontWithName:#"HelveticaNeue-Thin" size:15.0f]];

Setting a custom font for UIBarButton works in one version but not another

Recently I was looking to use the custom font SS-Standard in a iOS application. After finding that the PostScript name is SSStandard, adding the font ttf file to the project and adding to the .plist, I can change a UILabel by calling:
[myLabel setFont:[UIFont fontWithName:#"SSStandard" size:fontSize]];
This however only works in iOS7, and to make it work in iOS6 (and possibly below, I haven't tested though) I have to replace the above with:
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:myString
attributes:#{
NSFontAttributeName: [UIFont fontWithName:#"SSStandard" size:iconFontSize],
NSLigatureAttributeName: #2
}];
myLabel.attributedText = attributedString;
Now this all works fine, however I'm also trying to set a custom font within a UIBarButton. I can do this for iOS7:
NSDictionary *barButtonAppearanceDict = #{
NSFontAttributeName : [UIFont fontWithName:SYMBOL_SET_NAME size:15],
NSLigatureAttributeName : #2
};
[button setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
But for iOS6 it doesn't load the new font. I was wondering if anyone has ever come across this (with any custom font).

How do I set the size of the text I'm drawing here?

I'm drawing some text using the code below. How do I set the size of this text?
NSDictionary *attrs =
#{ NSForegroundColorAttributeName : [UIColor grayColor],
};
NSString *currentRank = #"Sample text";
[currentRank drawAtPoint:CGPointMake(100, 100) withAttributes:attrs];
Looking at the docs it seems as though the font name contains the size
NSFontAttributeName
NSFont
Default Helvetica 12-point
Available in OS X v10.0 and later.
Declared in NSAttributedString.h.

Resources