Reputation: 1266
I want to set bold font on UILabel
. I generate label by coding. when i try to set bold font on label ios set system regular font but i want to set 'Noto sans-Bold' font. In storyboard set font completely.
My code is
UILabel *lblName=[[UILabel alloc]initWithFrame:CGRectMake(0, 25, 100, 21)];
lblName.text=@"Hello World";
[lblName setFont:[UIFont fontWithName:@"Noto Sans-Bold" size:15.0]];
[self.view addSubview:lblName];
Upvotes: 2
Views: 2244
Reputation: 7602
lblname.font = [UIFont fontWithName:@"Noto Sans-Bold" size:18];
and one more thing check your font correctly it is available in list or not.
Here is a list of available fonts .
EDIT:- or if you want to set font which not available in xcode then you have to first install it in XCode please follow this tutorial.
As said by Jilouc follow this procedure.
- Add the font files to your resource files
- Edit your
Info.plist
: Add a new entry with the keyFonts provided by application
.- For each of your files, add the file name to this array
On the example below, I've added the font "DejaVu Sans Mono":
In your application you can the use
[UIFont fontWithName:@"DejaVuSansMono-Bold" size:14.f]
.Or if you want to use it in html/css, just use
font-family:DejaVu Sans Mono;
Upvotes: 2
Reputation: 7252
If you haven't got the formatting of your font title correct, it will automatically default back to system font.
The issue is with your font name and since Noto isn't native it's going to be difficult to know exactly what name you need to provide.
Make sure you have added that font to your project.
You can check your available fonts by running this code:
SWIFT
for familyName in UIFont.familyNames() {
print("\n-- \(familyName) \n")
for fontName in UIFont.fontNamesForFamilyName(familyName) {
print(fontName)
}
}
OBJECTIVE-C
for (NSString *familyName in [UIFont familyNames]){
NSLog(@"Family name: %@", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"--Font name: %@", fontName);
}
}
Upvotes: 4