本文介绍了如何获得UILabel的重量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
情节提要中的用户或以编程方式可以将字体粗细设置为常规,半粗体等.
User from storyboard or programatically can set font weight as regular, semi bold etc.
我想读取任何字体标签的重量.
I want to read weight for any font label.
我尝试了 po label.font.description
,并且font-weight存在,但是没有暴露的变量可以从字体中获得权重.
I tried po label.font.description
and font-weight is there and but there is no exposed variable to get weight from font.
有可能吗?
推荐答案
要获取字体粗细字符串名称,请使用字体描述符并传入face属性.
To get the font weight string name, use the font descriptor and pass in the face attribute.
Swift 4.2
let font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold)
let face = font.fontDescriptor.object(forKey: UIFontDescriptorFaceAttribute) as! String
print("face: \(face)")
快捷键3
let font = UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)
let face = font.fontDescriptor.object(forKey: UIFontDescriptorFaceAttribute) as! String
print("face: \(face)")
这篇关于如何获得UILabel的重量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!