I'm trying to reduce the weight of font in UILabel text.
I'm using Helvetica font, still i want the text more thinner.
how can i reduce the thickness of UILabel text font weight?
You can set the font to a different variant in the same family, for instance Helvetica-Light (where by default you get Helvetica-Regular). iosfonts.com provide a nice site for viewing font options.
You can't set an arbitrary weight for any font. Some fonts have a bold and regular variant. A smaller number also have a "light" variant. As the other poster said, if the font is one of those that has a light variant, you can select that, but you can't arbitrarily reduce the weight of a font.
You need to reduce the pointSize of the UIFont used by the UILabel:
UILabel *label; // Your Label
UIFont *font = label.font;
label.font = [font fontWithSize:(font.pointSize - 4)];
This example reduces the font by 4 points.
Related
In my case UILabel size can change dynamical . If it is bigger I want to have the best fitting, biggest font size. Is it possible to set it in Storyboard or I need calculate the best one programmatically?
If you have more than 1 word in the label, you can set a very high font size and, set AutoShrink -> Minimum Font Size to a small size. Then in run time app will auto shrink to maximum possible font size. But this doesn't work for if you only have a single word.
I have created a studio for user to create different type of logos. It also contains a couple of labels. I want to allow the user to convert those label font to bold and italic but I am having an issue that the fonts I am using dont have either Italic or Bold in their families. I tried a couple of solutions which contains:
UIFontDescriptor * fontD = [font.fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
selectedLabel.font = [UIFont fontWithDescriptor:fontD size:0];
but this changes my font to system font as no bold or italic font is found to it.
For Bold, I added some stroke so the font looks like bold which is ofcourse a bad practice but then again I got stuck for Italic. Is there any proper way that I can allow those fonts to be converted to Bold and Italic without having bold or italic in their family ?
Fonts I am using Aaargh, Average Sans, Cardinal, Comfortaa and others.
Is it possible to force a UIFont to be monospaced?
Specifically I'm using a font which does not contain monospaced numbers (tabular numerals). Creating a modified font object which is monospaced and adding that font to the numeric segments of attributed strings would work great.
Another solution may be to add custom attributes to an attributed string and modify what is handling the layout of the text to use a fixed size for glyphs in particular ranges.
Things that Haven't Worked:
There are a number of questions that propose solving similar problems by overriding -drawRect: or -drawTextInRect: on a UILabel (see: Is it possible to alter the letter-spacing/kerning of a font with Cocoa Touch?). This seems like an insane solution and would be prohibitively complex if a string mixes monospaced and not-monospaced fonts.
There are also number of questions which suggest, specifically in regards to numerals, creating a font with a font descriptor with certain font features enabled. (see Displaying proportionally spaced numbers (instead of monospace / tabular) on iOS). This seems only to work in fonts which include these features. The font I'm using does not include these features and they have no effect. The font features can be checked by using something like NSLog(#"%#", CTFontCopyFeatures ( ( __bridge CTFontRef ) myFont ));
In iOS 7, users can manipulate their fonts from the control panel, something designed to help (amongst other things) visually impaired users.
I'm trying to work with the new paradign by using the new methods created to support that functionality. For the most part, it's easy enough -- just use [label setFont:[UIFont prefferedFontForTextStyle:UIFontTextStyleHeadline]] or whatever format you need.
But occasionally I need to adjust those. For example, maybe headline needs to be a bit bigger. I can use this answer to that. Unfortunately, I can't figure out how to apply that answer to other changes, such as simply bolding the font without changing the size.
You can try this:
UIFontDescriptor *descriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline];
/// Add the bold trait
descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
/// Pass 0 to keep the same font size
UIFont *font = [UIFont fontWithDescriptor:descriptor size:0];
For example I have fixed width label with 4 word text with a fix font size. but when 4 (small )word sentence "this is my car" and other 4 (large)words sentence "elephant most beautiful animal" with same size font.
so small 4 words sentence will be adjusted in fixed label width but bigger word sentence "elephant most beautiful animal" will cause the problem in that UILabel text
How can I dynamically calculate the size of sentence words and adjust font size of text to be fixed in UIlabel.
please guide...
Probably you're looking for the adjustsFontSizeToFitWidth property.
in interface builder click on the label and set the minimum font size. if it is not in interface builder, do this
[Label setAdjustsLetterSpacingToFitWidth:YES];
[Label setMinimumScaleFactor:2];
[Label setAdjustsFontSizeToFitWidth:YES];
these shrink the font size depending on the length of the sentence. The first tightens the letter spacing and the second scales the font down by 2. The 3rd adjusts the font size.