iOS17适配指南之UIFont.TextStyle、UITex
2023-06-11 本文已影响0人
YungFan
UIFont.TextStyle
增加了新的超大字体样式extraLargeTitle
与extraLargeTitle2
。
import UIKit
class ViewController: UIViewController {
lazy var label1: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 100, width: UIScreen.main.bounds.width, height: 100))
label.text = "WWDC 23 推出了 Xcode 15,发布了 iOS 17。"
label.numberOfLines = 0
label.font = .preferredFont(forTextStyle: .body)
label.adjustsFontForContentSizeCategory = true
return label
}()
lazy var label2: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 100))
label.text = "WWDC 23 推出了 Xcode 15,发布了 iOS 17。"
label.numberOfLines = 0
label.font = .preferredFont(forTextStyle: .extraLargeTitle2)
label.adjustsFontForContentSizeCategory = true
return label
}()
lazy var label3: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 300, width: UIScreen.main.bounds.width, height: 150))
label.text = "WWDC 23 推出了 Xcode 15,发布了 iOS 17。"
label.numberOfLines = 0
label.font = .preferredFont(forTextStyle: .extraLargeTitle)
label.adjustsFontForContentSizeCategory = true
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(label1)
view.addSubview(label2)
view.addSubview(label3)
}
}
UIFont.TextStyle
UITextField
增加了birthdate
与creditCard
相关的 textContentType(输入时可以根据设置的类型提供自动填充的选项)。
import UIKit
class ViewController: UIViewController {
lazy var birthdayTF: UITextField = {
let textfield = UITextField(frame: CGRect(x: 100, y: 100, width: 200, height: 34))
textfield.borderStyle = .roundedRect
textfield.textContentType = .birthdate
return textfield
}()
lazy var cardTF: UITextField = {
let textfield = UITextField(frame: CGRect(x: 100, y: 150, width: 200, height: 34))
textfield.borderStyle = .roundedRect
textfield.textContentType = .creditCardNumber
return textfield
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(birthdayTF)
view.addSubview(cardTF)
}
}