Skip to content

Instantly share code, notes, and snippets.

@liruqi
Created January 20, 2016 07:24
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 liruqi/06810931d0b7c8cd02b6 to your computer and use it in GitHub Desktop.
Save liruqi/06810931d0b7c8cd02b6 to your computer and use it in GitHub Desktop.
Put to adjacent view in the horizontal middle of screen
// No working anyway
CGSize screenSz = [UIScreen mainScreen].bounds.size;
CGSize leftSz = [self.haveAccountLabel intrinsicContentSize];
CGSize rightSz = [self.signInButton intrinsicContentSize];
CGFloat contentWidth = leftSz.width + rightSz.width + 8;
CGFloat x = (screenSz.width - contentWidth) / 2;
if (x < 0) {
NSLog(@"Text overflow %lf > %lf", contentWidth, screenSz.width);
} else {
_haveAccountLabel.translatesAutoresizingMaskIntoConstraints = YES;
_signInButton.translatesAutoresizingMaskIntoConstraints = YES;
CGRect f = _haveAccountLabel.frame;
f.origin.x = 0;
f.size.width = x + leftSz.width;
self.haveAccountLabel.frame = f;
f = self.signInButton.frame;
f.origin.x = x + leftSz.width + 8;
f.size.width = screenSz.width - f.origin.x;
self.signInButton.frame = f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment