I have a label which I want to have the same relative position on the screen, no matter what device is used. E.g. the label is positioned 10% off from the views top margin and 30% off from the views left margin.
A constant will always do the positioning e.g. 150 px off from the views margin and will therefore be greater for devices with a small resolution, while devices with a bigger resolution will only have a smaller distance...
Is there a way to realize this programmatically e.g. with the help of SnapKit?
My code currently looks like this:
import UIKit
import SnapKit
class worldViewController: UIViewController {
lazy var correctFieldNew = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(correctFieldNew)
correctFieldNew.backgroundColor = UIColor.blueColor()
correctFieldNew.snp_makeConstraints { (make) -> Void in
make.size.equalTo(CGSizeMake(90, 30))
}
}
}
I feel like I have to use the multiplier here, but the label does not move an inch when I write something like:
make.top.equalTo(self.view).multipliedBy(0.1)
The correct way is to use:
make.top.equalTo(self.view.snp_bottom).multipliedBy(0.1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With