While using Interface builder & iOS7 UIFontTextStyleHeadline
I set my headline label to UIFontTextStyleHeadline
(I guess it can be done also with the following code:)
myHeadlineTextLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
Q:
this works well, yet I would like to have the same functionality only using HelveticaNeue-Thin
just as an example:
titleCustomLabel.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:(**Dynamic font size as the user defined in his setting**)];
what would be an elegant way to do so?
UIFont has the fontSize property. You can make use of that.
titleCustomLabel.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline].pointSize];
(don't use fontSize at the end)
Related
What I want to do is change the font size.
I know below statement will change the font size, but it changes the font name because we are using systemFontOfSize
[UIFont systemFontOfSize: 13.0];
I know alternate option is as mentioned below.
[myLabel setFont:[UIFont fontWithName:#"Helvetica-Bold" size:13.0]];
but I don't want to use fontWithName as I am setting that in IB.
I don't want to play with font name as my app is multi-language and hence I don't want to play with font name.
Any idea how can I just change fontsize and don't change the fontname.
Too bad that the font metrics properties of UIFont are readonly. It'd be nice if they could be adjusted dynamically without having to do this below:
UIFont * fontFromLabel = myLabel.font;
// now we have the font from the label, let's make a new font
// with the same font name but a different size
if(fontFromLabel)
{
// 13, or whatever size you want
UIFont * newFontForLabel = [UIFont fontWithName: fontFromLabel.fontName size: 13.0f];
if(newFontForLabel)
{
[myLabel setFont: newFontForLabel];
}
}
I'm having an issue where I allow the user to select a font for a label in my project, but then when the user sets the size of that label (using a different button), the label resets to a default font. I'd like to be able to retain the font that the user had applied while still allowing the user to change the font size. Any help is appreciated, thanks!
Here's my code..
-(IBAction)setFont{
[userText setFont:[UIFont fontWithName:#"Arial-BoldMT" size:50.0]];
//I had to add a size when setting the font or else I got an error
}
-(IBAction)setFontSize{
[userText setFont:[UIFont systemFontOfSize:24]];
}
Just use the fontWithSize: method on the label's current font:
- (IBAction)setFontSize {
// Keep the same font but change its size to 24 points.
UIFont *font = userText.font;
userText.font = [font fontWithSize:24];
}
The function [UIFont systemFontOfSize:] will always return default system font. You can just make use of the same function that you call in setFont which is [UIFont fontWithName:size:].
I'm trying to create a custom “Change font” NSPopupButton for a Mac App (not an iOS App). I can detect a change in font selection:
long fontItemIndex = [fontPopup indexOfSelectedItem];
NSMenuItem *fontItem = [fontPopup itemAtIndex:(int)selectedFontItemIndex];
NSString *fontName = [selectedFontItem title];
Given this NSString of a font name, I cannot seem to find out how to actually change the selected text in my NSTextView textView to this new font.
I'm simply dazzled by the official documentation: it seems convertFont:toFamily: is what I need. When I do this:
NSFont *font = [NSFont fontWithName:fontName size:12.0];
[textView setFont:font];
It sets all text in the text view, not just the selected text. But when I do this:
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager convertFont:[fontManager selectedFont] toFamily:fontName];
it doesn't do a thing. What am I missing?
Inside a NSTextView is a NSTextStorage (a subclass of NSAttributedString) and you’ll have to modify the attribute named NSFontAttributeName.
First get the range where you want to change the font attribute:
NSRange selection = textView.selectedRange;
Now add the font attribute to the selection:
NSFont *font = [NSFont fontWithName:fontName size:12.0f];
[self.textView.textStorage addAttributes:#{NSFontAttributeName: font}
range:selection];
Depending on the contents of your NSPopUpButton it should be enough to call fontWithName:size: with title as the font name to get the just selected font. But if the method you already do doesn’t work, you’ll probably have to get a specific font from the font family name. availableMembersOfFontFamily: on NSFontManager will give you a list of all available fonts. You can use one of them to initialize a specific font.
Take a look at the setFont:range: method on NSText, the superclass of NSTextView.
(The ranges, of course, come from the selectedRanges property on NSTextView.)
This was all I needed to change all the text in my textview.
[textview setFont:[NSFont fontWithName:#"Courier" size:14]];
In a UITextView is it possible to set the fontname and then set it to bold?
I know that font name and size can be set using
fontWithName:(NSString *)fontName size:(CGFloat)fontSize
But once this is done how can i make it bold?
The system font on the iPhone is a good choice for many purposes. You can easily select it in a regular, bold or italic style using built-in font class methods. For example
UIFont *mainTitleFont = [UIFont boldSystemFontOfSize:14.0];
UIFont *subTitleFont = [UIFont SystemFontOfSize:14.0];
UIFont *textFont = [UIFont italicSystemFontOfSize:12.0];
But what if you want a font using both bold and italic at the same time, or a different typeface altogether? In that case, you can use the “fontWithName” method as follows.
UIFont *altFont = [UIFont fontWithName:#"Courier-Bold" size:14.0];
Reference
Use the Bold variant of the font, e.g. #"Helvetica-Bold" as the fontName. If using the default system font is ok for you, you can also use boldSystemFontOfSize: method instead.
UIFont *f = [UIFont fontWithName:#"Verdana-Bold" size:12];
yourTextView.font = f;
If you want to give font with name then you can refer below link. It have all font which are provided by iOS with their font names.
iOS Fonts
Thanks.
How can I change a textview font and font size..
I've tried this but it doesnt seem to change anything...
typingText.font = [UIFont fontWithName:#"Marker Felt Thin" size:64.0f];
Thanks!
The actual name of the font is "MarkerFelt-Thin".
typingText.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:64.0f];