var PT: CGFloat = 0;
override func viewDidLoad() {
super.viewDidLoad()
setPoints();
}
func setPoints() {
let screenBounds = UIScreen.main.bounds
let screenScale = UIScreen.main.scale
let screenSize = CGSize(width: screenBounds.size.width * screenScale, height: screenBounds.size.height * screenScale)
let nativeBounds = UIScreen.main.nativeBounds
let nativeScale = UIScreen.main.nativeScale
let pxScreenWidth:CGFloat = nativeBounds.width;
let ptScreenWidth:CGFloat = screenBounds.width;
PT = pxScreenWidth/ptScreenWidth/nativeScale;
}
How to use:
let label: UILabel = UILabel(frame: CGRect(x: 15 * PT, y: 10 * PT, width: self.view.frame.width - 30 * PT, height: self.view.frame.height - 20 * PT))