一些技术相关:https://zrzzzz.github.io/
UIView.superView()
func superView<T: UIView>(of: T.Type) -> T? {
for view in sequence(first: self.superview, next: { $0?.superview }) {
if let father = view as? T {
return father
}
}
return nil
}
用于寻找父View, 不过只能寻找到第一个就是了
UILabel.fontSuitToFrame()
func fontSuitToFrame() {
let aView = self.sizeThatFits(CGRect.zero.size)
guard aView.width * aView.height != 0 else { return }
let rate1 = self.frame.width / aView.width
let rate2 = self.frame.height / aView.height
let rate = rate1 > rate2 ? rate2 : rate1
self.font = .systemFont(ofSize: self.font.pointSize * rate)
}
宽高哪个窄就铺满哪一个
DyColor(light: UIColor, dark: UIColor) -> UIColor
func DyColor(light: UIColor, dark: UIColor) -> UIColor {
return UIColor(dynamicProvider: { (trait) -> UIColor in
return trait.userInterfaceStyle != .dark ? light : dark
})
}
两种登录方式,输入不对或者密码错误时会弹窗