- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 UIFont
具有以下属性:
我正在使用系统字体 ( San Francisco
),它支持所有这些功能。
据我所知,唯一的方法是使用多个 UIFontDescriptor
.
这是我正在使用的代码:
extension UIFont {
var withSmallCaps: UIFont {
let upperCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kUpperCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kUpperCaseSmallCapsSelector
]
let lowerCaseFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kLowerCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier : kLowerCaseSmallCapsSelector
]
let features = [upperCaseFeature, lowerCaseFeature]
let smallCapsDescriptor = self.fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.featureSettings : features])
return UIFont(descriptor: smallCapsDescriptor, size: pointSize)
}
var withMonospacedDigits: UIFont {
let monospacedDigitsFeature = [
UIFontDescriptor.FeatureKey.featureIdentifier : kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier : kMonospacedNumbersSelector
]
let monospacedDigitsDescriptor = self.fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.featureSettings : [monospacedDigitsFeature]])
return UIFont(descriptor: monospacedDigitsDescriptor, size: pointSize)
}
}
我应该能够通过这行代码获得具有前面提到的所有特征的字体:
let font = UIFont.systemFont(ofSize: 16, weight: .regular).withSmallCaps.withMonospacedDigits
// OR
let font = UIFont.monospacedDigitSystemFont(ofSize: 16, weight: .regular).withSmallCaps
但由于某些原因,它不起作用。我无法让字体在具有等宽数字的同时具有小型大写字母。
我做错了什么?
最佳答案
多亏了reference document,我明白了为什么它不起作用。链接为 @Carpsen90 .
似乎数字间距
功能是独有的。
如文档中所述:
Features are classified as "exclusive" and "nonexclusive." This indicates whether several different selectors within a given feature type may be selected at once. Thus, it is possible to have both common and rare ligatures turned on, whereas it is impossible to display a given fraction as simultaneously vertical and diagonal.
因此同时拥有等宽数字+小型大写字母功能是不可能的。
我看错了文档。该功能的选择器是排他的。但不是全部功能。所以应该是可以的。
关于ios - UIFont 等宽数字+小型大写字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51828496/
如果我有一个 UIFont 对象,是否可以将它转换为粗体?我不知道字体名称,我只有一个 UIFont 对象。我想要的是像这样的功能 UIFont *boldFontFromFont(UIFont *i
所以我今天晚上将我的 XCode 更新到了 7.3。 在我的一个项目中,我设置字体的几个标 checkout 现以下错误: '(name: String, size: CGFloat) -> UIFo
最近我注意到滚动的性能正在减慢。我追踪了问题,发现原因是使用了 UIFont(descriptor:size:) 创建的字体。构造函数。我更改了 UIFont(name:size:) 的构造函数我的问
我正在编写一个 iPhone 应用程序,需要渲染包含 diacriticals 的 i18n 文本。 (波浪号、重音符号等)。 Apple 提供 UIFont可用于获取给定字体/字体大小组合的前导、上
我使用的UIFont支持我想要的符号。我如何以编程方式在代码中键入该符号? UILabel *label = [ [UILabel alloc ] initWithFrame:frame]; scor
我已向 UIFont 类添加了方法.h 文件 @interface UIFont (UIFont_CustomisedFont) +(UIFont*)bold11; +(UIFon
UIFont 提供 +preferredFontForTextStyle:方法根据用户选择的内容大小类别和给定的 UIFontTextStyle 获取具有适当大小的字体实例。 . 我想做的是获取给定文
在我的应用程序中,我想使用 stylistic alternate font对于 'a' 而不是 system font . 附件 screenshot这解释了字体的不同渲染。 如何为 UILabel
UIFont 有方法获取常规字体 (systemFontOfSize) 或粗体字体 (boldSystemFontOfSize),但是如何获取“细系统字体” “可以通过 Storyboard获得吗?
在 UITableViewCellDefault 样式中,标题字体是 20 点 Helvetica 普通样式字体,粗体。如何在代码中创建相同的字体? 我正在考虑创建一个 UITableViewCell
我正在尝试在 iPhone 应用程序中设置用户选择字体的可能性。 我已经使用 UIFont 类取得了进展。这是我的问题:当选择字体系列中的字体时,我如何知道用户对大小的可能性?有没有办法列出它们?我在
我有一个字体名称:HelveticaNeueLTStd-Roman 55.otf。我将它添加到我的 info.plist 文件中。 当我写代码时: UIFont *fontHalvetikaNeueL
有没有办法查询 UIFont 中的字符总数?例如,像这样: UIFont.systemFont(ofSize:16).count ?我正在构建一个应用程序来浏览 UIFont 中的所有字符。我想知道为
任何人都可以确认 UIFont(Cocoa-Touch/iOS 的)是否线程安全?也就是说,在主线程之外的线程内使用但实例不在线程之间共享是否安全? 问题是我正在这样做,并且我在 [NSString
我正在通过自定义函数为我的 View 中的所有 subview (例如UILabels)设置自定义字体。但是,如果我尝试仅通过 更正特定 UILabels 的字体大小 [lbl_EXAM_Statis
我正在尝试在 UILabel 中使用 UIFont fontWithName:size:,但在 250 点以上的尺寸下分辨率很差。我在使用自定义字体和系统字体时遇到问题。我对 UITextView 也
我对自定义字体有疑问。即Tw Cen MT.ttf 和这里一样的问题: Custom font not showing on device, but does on simulator 除了给定的解决
是否可以继承 UIFont 并用另一个(或字体描述符)初始化它?问题是,我不能调用 super.init(descriptor:size:) 进行初始化,因为它是一个方便的初始化程序。这样做的目的是更
我想知道是否应该缓存 [UIFont fontWithName:@"myfont"size:24]。我在很多地方重复使用这种字体。我想知道 iOS 是否已经为我缓存了这个,因为字体缓存在操作系统级别非
我在我的 tableview 中做了一些文字换行,因为一些值太大以至于超出了屏幕的边缘。 但是,字体、大小和粗体与表格 View 的默认设置不匹配,希望有人能帮我解决这个问题。 这就是我设置字段的方法
我是一名优秀的程序员,十分优秀!