How do I align a label vertical center in XCode 6 How do I align a label vertical center in XCode 6 ios ios

How do I align a label vertical center in XCode 6


click on Align button on bottom toolbar in IB then select Horizontal or Vertical center. First you might want to fix width and height as well, if you want to preserve size.

enter image description here


For an explanation of why this happens:

Whenever you add constraints to a view in interface builder you are telling IB that you want to opt in to auto layout and now you have to take full control of the layout. The reason you see the label at the top of the superview is because you haven't added any constraints that determine the label's location within the superview. See mohacs answer on how to add the constraints.


In case someone still need that here's how you can do programatically

let centerCoordinate = self.view.frame.maxY - (self.view.frame.maxY/2.0)label.frame = CGRectMake(centerCoordinate,100, 50, 50)


matomo