Questions tagged [uifontdescriptor]

UIFontDescriptor objects provide a mechanism to describe a font with a dictionary of attributes. This font descriptor can be used later to create or modify a UIFont object.

UIFontDescriptor objects provide a mechanism to describe a font with a dictionary of attributes. This font descriptor can be used later to create or modify a UIFont object.

Font descriptors can be archived and unarchived. Font descriptors have a font matching capability, so that you can partially describe a font by creating a font descriptor with, for example, just a family name.

35 questions
21
votes
5 answers

UIFontWeightTrait and UIFontDescriptorFamilyAttribute Ignored when creating UIFont from UIFontDescriptor

Given the following code and a device running iOS 7.1 or later: NSDictionary *fontTraitsDictionary = @{UIFontWeightTrait : @(-1.0)}; NSDictionary *attributesDictionary = @{ UIFontDescriptorFamilyAttribute :…
jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
18
votes
6 answers

Add custom weight to iOS Font descriptor in Swift

This seems like it should be rudimentarily easy, but for whatever reason it's not working. I've read similar posts on SO and it seems like there might be an issue with the Font Traits dictionary? Is this an issue or am I just completely missing…
Tim Sanders
  • 831
  • 2
  • 15
  • 24
12
votes
4 answers

A better way to use Dynamic Type with a custom font in Swift 3/iOS10

I tried two ways: Method 1: label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) label.adjustsFontForContentSizeCategory = true This works fine, even when the preferred text size is changed in the Settings, the text size changes…
ielyamani
  • 17,807
  • 10
  • 55
  • 90
8
votes
1 answer

Displaying proportionally spaced numbers (instead of monospace / tabular) on iOS

I am rendering numbers in iOS (targeting 7 and up) by storing them in an NSAttributedString and rendering with "drawAtPoint:". I am using Helvetica Neue. I have noticed that digits of numbers drawn like this are not proportional – the glyphs all…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
6
votes
2 answers

How do I find the existing UIFontTextStyle of a UILabel?

I'm currently creating an extension on UILabel to facilitate observing dynamic type. Once a UIContentSizeCategoryDidChangeNotification is received, I'd like my selector to set the label's font by using self.font =…
lauragone
  • 63
  • 6
6
votes
2 answers

Font Descriptor returns nil in iOS 8

The following code works fine in iOS 7, but doesn't return bold or italic font in iOS 8. It is ok for Helvetica Neue, but doesn't work for Arial font. UIFontDescriptor *descriptor1 = [UIFontDescriptor…
Metodij Zdravkin
  • 914
  • 1
  • 14
  • 23
4
votes
0 answers

Swift - fontDescriptor returns NIL when making font to Italic in iOS 12

I have been struggling for a while now about this fontDescriptor.withSymbolicTraits it returns nil whenever I try to use Bold or Italic. I'm using this code below: func withTraits(traits:UIFontDescriptor.SymbolicTraits) -> UIFont { let…
Pepeng Hapon
  • 357
  • 1
  • 17
4
votes
0 answers

iOS font family API doesn't return systemFontOfSize names

I need to dump all the fonts (the names of the fonts and their variants) available on a device (9.x) The code seems simple enough: NSMutableArray *arr = [@[] mutableCopy]; NSArray *familyNames = [UIFont familyNames]; for (NSString *fn in…
Avba
  • 14,822
  • 20
  • 92
  • 192
4
votes
2 answers

Get UIFont for content size category

UIFont provides the +preferredFontForTextStyle: method to get a font instance with the proper size based on the user's selected content size category and the given UIFontTextStyle. What I would like to do is get a font for a given text style and…
mokagio
  • 16,391
  • 3
  • 51
  • 58
4
votes
2 answers

Why do some iOS font families not support UIFontDescriptorTraitBold?

The method I'm trying to use to get a bold faced iOS UIFont given a font family name only seems to work for some fonts. For example: UIFont* font = [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12]; NSLog(@"A: Font name: %@", [font…
devx
  • 307
  • 1
  • 14
3
votes
1 answer

SwiftUI.Font How to apply UIFontDescriptor.FeatureKey.featureIdentifier

A UIFont can easily be setup via the font descriptor, e.g. let settings: [UIFontDescriptor.FeatureKey: Int] = [ .featureIdentifier: kStylisticAlternativesType, .typeIdentifier: 2] let descriptor =…
benrudhart
  • 1,406
  • 2
  • 13
  • 25
3
votes
1 answer

swift alternative for fontDescriptorWithSymbolicTraits ios 8 bug

I'm trying to create a Swift custom text editor (lite version) and got stuck on iOS 8 fontDescriptorWithSymbolicTraits bug, returning nil. Are there any Swift workarounds? I've created a small project sample here , you can download and run the…
el.severo
  • 2,202
  • 6
  • 31
  • 62
2
votes
1 answer

How to use UIFontDescriptor when CTFeatureTypeIdentifier is not available

I use the following snippet to get the font features: let font = UIFont.systemFont(ofSize: 16) let features: NSArray = CTFontCopyFeatures(font)! print("properties = \(features)") So If I see this: { CTFeatureTypeExclusive =…
Gizmodo
  • 3,151
  • 7
  • 45
  • 92
2
votes
1 answer

Variable fonts in iOS 14

The following code allows to create a font with different weights. func makeFont(weight: CGFloat, size: CGFloat) -> UIFont { var attributesDict = [String: Any]() attributesDict["Weight"] = weight /* Rubik-Light - is a variable font */ …
RPlay
  • 301
  • 2
  • 10
2
votes
2 answers

How to specify a minimum UIContentSizeCategory for UIFontMetrics?

I have a method for creating an auto-scaling font based on Dynamic Type that looks like so: extension UIFont { public static func getAutoScalingFont(_ fontName: String, _ textStyle: UIFont.TextStyle) -> UIFont { // getFontSize pulls from…
WongWray
  • 2,414
  • 1
  • 20
  • 25
1
2 3