Skip to content

Instantly share code, notes, and snippets.

@D-32
Created November 1, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-32/217d89cf87c2a6615392 to your computer and use it in GitHub Desktop.
Save D-32/217d89cf87c2a6615392 to your computer and use it in GitHub Desktop.
Correctly vertically center a text field
CGFloat topLetterPadding = self.nameLabel.font.ascender - self.nameLabel.font.capHeight;
NSLayoutConstraint *nameLabelCenterConstraint = [NSLayoutConstraint constraintWithItem:self.nameLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:roundf(-(topLetterPadding / 2))];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment