Software-defined position of the Swift element

I have a tag defined in the Storyboard, and I'm trying to change its position based on programs. There are already some existing questions on SO that seem to solve this problem, but none of the solutions work (i.e. the Label does not move). I removed all existing label restrictions to no avail. I tried:

class LandingViewController: UIViewController {

    @IBOutlet weak var titleLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        titleLabel.frame = CGRectMake(100, 25, titleLabel.frame.size.width, titleLabel.frame.size.height)
        }

I also tried

titleLabel.center = CGPointMake(120, 150)

instead titleLabel.frame

Did I miss something?

+4
source share
2 answers

AutoLayout , , translatesAutoresizingMaskIntoConstraints, false, , . , , .

// , true . , , AutoLayout, , , , , , , .

, , , , - AutoLayout. , , .

+5

? , ( , UIlabel )

 var tempLabel:UILabel
 override func viewDidLoad() {
      super.viewDidLoad()

     //gets screen frame size
     var fm: CGRect = UIScreen.mainScreen().bounds

     //creates a temp UILabel
     tempLabel = UILabel(frame:  CGRectMake(0, fm.frame.size.height, fm.size.width, fm.size.height))

     //aligns the UIlabel to center
     tempLabel.textAlignment = NSTextAlignment.Center

    //adding UIlabel to view
    view.addSubview(tempLabel)
}
+1

Source: https://habr.com/ru/post/1598603/


All Articles