beachCode
beachCode

Reputation: 3520

Swift: centering a label with another control in the way

I'm wondering if I can move a label to the center of a view even if there are other hidden controls in the way. I'm using Swift 1.2 and I'm using auto-layout for the initial position.

So I really have two questions:

  1. How can I move a label to the center? I've found plenty of examples of moving to a particular location based on the original position. I just want the center. I tried this:

     self.labelTest.center = self.view.center
    
  2. Will it work 'over' hidden controls or do I have to move them too? i.e., to get them out of the way Thanks

Upvotes: 1

Views: 341

Answers (1)

Dean Severell
Dean Severell

Reputation: 11

self.labelTest.center = self.view.center

This instruction won't be affected by the existence of any other views on your self.view if autolayout is off. However if autolayout is enabled depending on what constraints you've set they may interfere with the positioning of your views. So either turn off AutoLayout or ensure the constraints don't hinder your view being centered.

Upvotes: 1

Related Questions