-2
UILabel
'전체 글꼴 크기는 전체 응용 프로그램의 다른 iPhone 장치 크기를 기반으로 설정할 수 있습니까? 나는이 목적을 위해 각 컨트롤의 사용자 정의 클래스를 사용하고다른 iPhone 장치의 자동 변경 글꼴 크기
UILabel
'전체 글꼴 크기는 전체 응용 프로그램의 다른 iPhone 장치 크기를 기반으로 설정할 수 있습니까? 나는이 목적을 위해 각 컨트롤의 사용자 정의 클래스를 사용하고다른 iPhone 장치의 자동 변경 글꼴 크기
아래 스크린 샷에서 볼 수 있듯이
class Label: UILabel {
@IBInspectable var iPhoneFontSize:CGFloat = 0 {
didSet {
overrideFontSize(fontSize: iPhoneFontSize)
}
}
@IBInspectable
public var cornerRadius: CGFloat = 2.0 {
didSet {
self.layer.cornerRadius = self.cornerRadius
}
}
@IBInspectable
public var borderWidth: CGFloat = 0 {
didSet {
self.layer.borderWidth = self.borderWidth
}
}
@IBInspectable
public var borderColor: UIColor = .clear {
didSet {
self.layer.borderColor = self.borderColor.cgColor
}
}
private func overrideFontSize(fontSize:CGFloat){
let currentFontName = self.font.fontName
var calculatedFont: UIFont?
let bounds = UIScreen.main.bounds
let height = bounds.size.height
switch height {
case 480.0: //Iphone 3,4,SE => 3.5 inch
calculatedFont = UIFont(name: currentFontName, size: fontSize * 0.7)
self.font = calculatedFont
break
case 568.0: //iphone 5, 5s => 4 inch
calculatedFont = UIFont(name: currentFontName, size: fontSize * 0.8)
self.font = calculatedFont
break
case 667.0: //iphone 6, 6s, 7, 7s => 4.7 inch
calculatedFont = UIFont(name: currentFontName, size: fontSize * 0.9)
self.font = calculatedFont
break
case 736.0: //iphone 6+, 6s+, 7+, 7s+ => 5.5 inch
calculatedFont = UIFont(name: currentFontName, size: fontSize)
self.font = calculatedFont
break
default: // New devices
calculatedFont = UIFont(name: currentFontName, size: fontSize)
self.font = calculatedFont
break
}
}
}
그런 다음 스토리 보드에서 가장 높은 해상도 iPhoneFontSize 속성 값을 설정합니다.