I looked at a few examples here on OS and also followed this one but what I wanted to know is how I can set a custom font for only one specific label.
This line is supposed to change the font:
[UIFont fontWithName:#"Cloister Black" size:64.0]
But I don't want everything to be affected. Any ideas how I do this?
Setting the font on a label is as easy as modifying that label's "font" property (and I've linked Apple's documentation for you).
E.G.:
labelIWantToModify.font = [UIFont fontWithName:#"Cloister Black" size:64.0];
And I'm hoping you're referring to that one specific label, and not a piece or part of the string that appears within the label, which is a separate (attributed string) thing.
Related
The Apple documentation says that for iOS an app can use text styles and dynamic font type so text size automatically adjusts to the users reading preferences.
I have a text style Body and set Dynamic Type to true so that it automatically adjust the text size. This works good.
This text I would also like to make appear bold. I haven't found a way yet how to achieve this either by code or in the Interface Builder.
Is there a way to achieve a "bold dynamic font type"?
Ok, it seems the documentation provides a hint. For using custom fonts, I consider a bold font as a custom font now, one can use the UIFontMetrics class.
If I pass a "bold custom font" to the scaledFontForFont method of UIFontMetrics class I get the desired result with the dynamic font type UIFontTextStyleBody.
UIFont* boldSystemFont = [UIFont boldSystemFontOfSize:17];
myLabel.font = [[UIFontMetrics metricsForTextStyle:UIFontTextStyleBody] scaledFontForFont:boldSystemFont];
So far I only see this way using code. No idea if this could somehow be setup in the Interface Builder as well.
I have custom Chivo font, added via cocoapod.
So, in xib I can find it using Title Plain, as you can see:
But if I need to use Attributed Title (for example to use 2 types: regular and bold in same string),
I can't find Chivo font:
So how to fix this? I sure can use it from code, but wonder if it can work in described way.
Thanks for help!
I'm trying to set a specific part of my label to bold and italic with NSMutableAttributedString, but I can only get one or the other. The font that I'm using is Clear Sans. Setting the entire label's font on the storyboard to Bold Italic works fine, but I only need part of it. So I used
for family in UIFont.familyNames() {
print("\(family)\n\t\(UIFont.fontNamesForFamilyName(family))")
}
to make sure it's there, and I found
Clear Sans
["ClearSans", "ClearSans-Bold", "ClearSans-Italic"]
For some reason, it's not in here but it is in the storyboard. So I tried to use this answer, but it crashes, I assume for the same reason that I didn't find ClearSans-BoldItalic, but I don't know why it's not in there.
Finally, I tried to just "stack" the two, like so
let bold = UIFont(name: "ClearSans-Bold", size: 20)
let italic = UIFont(name: "ClearSans-Italic", size: 20)
attributedCaption.addAttribute(NSFontAttributeName, value: bold!, range: (imageContainer.caption as NSString).rangeOfString(matchString))
attributedCaption.addAttribute(NSFontAttributeName, value: italic!, range: (imageContainer.caption as NSString).rangeOfString(matchString))
but all this does is use the last attribute, which is what I had expected it to do.
Is there some other method I can use to do this so that I get both bold and italic to show on the same part of the label?
Edit
I wanted to include my fonts that are in the project, so it's clear that I've already imported them. The second image is the list of fonts on the storyboard. While it's covered up, the family is in fact Clear Sans.
Make sure bold italic version is also added to app's Info.plist under UIAppFonts ("Fonts provided by application") key.
UIFont.italicSystemFont(ofSize: 15.0)
UIFont.boldSystemFont(ofSize: 15)
if you want to custom font of label like fond system . you can try my solution .
it works good for swift 3
I want to add font image to and UILabel. I added new TTF file to my resource folder which is fontallo. Added project info Fonts fontallo.ttf.
Now I want to set those images which are inside the fontallo.
Please find the below images
[lbl_FontImage setFont:[UIFont fontWithName:#"fontello" size:30]];
Unable to set those image to UILabel. Need suggestion to resolve it.
I'm assuming that you have verified the font is loaded and set onto the label. If not you need to log all of the fonts loaded in the system, check it's there and find the correct font name to pass to UIFont.
You need to set the label text to a string containing the character you want. You generally need to know the character that the font is using, kind of like the location in the font file. Or, you can copy the character (from FontBook) directly into your code (though you might see a placeholder symbol in the code).
I'd say it's generally best not to copy and paste, but that's probably personal preference. Unicode is better to use. To get that you need a tool which will tell you the Unicode value of the character. Once you have that you can create the string and directly reference the character.
Make sure you add your font names to your project's .plist file:
Lets say I want to make only the text "Software" bold. Is there a way to achieve this without a custom alertview?
self.subHeadingLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
Check out dynamic text in ios7 . it has six different font styles. There is a good article here