Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // quick UIFontDescriptor test
- class AvenirTestVC: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- var avFamilyName: String = ""
- // let's make sure we have the Avenir Next font family
- for family in UIFont.familyNames {
- if family == "Avenir Next" {
- avFamilyName = family
- break
- }
- }
- if avFamilyName.isEmpty {
- fatalError("Avenir Next font family not found!!!")
- }
- let stackView = UIStackView()
- stackView.axis = .vertical
- stackView.spacing = 8
- stackView.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(stackView)
- let g = view.safeAreaLayoutGuide
- NSLayoutConstraint.activate([
- stackView.topAnchor.constraint(equalTo: g.topAnchor, constant: 40.0),
- stackView.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 16.0),
- stackView.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -16.0),
- ])
- let weights: [UIFont.Weight] = [
- .light, .regular, .medium, .semibold, .bold, .heavy,
- ]
- weights.forEach { w in
- let thisDescriptor = UIFontDescriptor(fontAttributes: [
- UIFontDescriptor.AttributeName.family: avFamilyName,
- UIFontDescriptor.AttributeName.traits: [
- UIFontDescriptor.TraitKey.weight: w
- ]
- ])
- let fnt: UIFont = UIFont(descriptor: thisDescriptor, size: 28)
- let label = UILabel()
- label.font = fnt
- label.text = fnt.fontName
- label.textAlignment = .center
- stackView.addArrangedSubview(label)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement