Created
December 7, 2017 18:52
-
-
Save meyusufdemirci/f6231fcf271160e0a9c4bb94d2651614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
enum ScreenType { | |
case iPhone4 | |
case iPhone5 | |
case iPhone6 | |
case iPhonePlus | |
case iPhoneX | |
case unknown | |
} | |
class CustomUILabel: UILabel { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
switch getScreenType() { | |
case .iPhone4, .iPhone5: | |
font = font.withSize(font.pointSize - 6) | |
break | |
case .iPhone6: | |
font = font.withSize(font.pointSize) | |
break | |
case .iPhonePlus, .iPhoneX: | |
font = font.withSize(font.pointSize + 6) | |
break | |
default: | |
break | |
} | |
} | |
func getScreenType() -> ScreenType { | |
switch UIScreen.main.nativeBounds.height { | |
case 960: | |
return .iPhone4 | |
case 1136: | |
return .iPhone5 | |
case 1334: | |
return .iPhone6 | |
case 2208: | |
return .iPhonePlus | |
case 2436: | |
return .iPhoneX | |
default: | |
return .unknown | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment