In iOS 8, we can design a different UI layout for each size class. The issue I\'m facing is, I\'ve designed a layout for Compact Width and Regular Height (size class for all
Thats the way how I did it. It's written in Swift 4 :)
enum DeviceSize {
case big, medium, small
}
protocol Fontadjustable {
var devicetype: DeviceSize { get }
func adjustFontSizeForDevice()
}
extension UILabel: Fontadjustable {
var devicetype: DeviceSize {
switch UIScreen.main.nativeBounds.height {
case 1136:
return .small
case 1334:
return .medium
case 2208:
return .big
case 2436:
return .big
default:
return .big
}
}
func adjustFontSizeForDevice() {
switch self.devicetype {
case .small:
self.font = font.withSize(font.pointSize)
case .medium:
self.font = font.withSize(font.pointSize + 5)
case .big:
self.font = font.withSize(font.pointSize + 10)
}
}
}
USAGE : myawesomeLabel.adjustFontSizeForDevice()