Hacker News new | past | comments | ask | show | jobs | submit login

Why not just use Auto Layout in pure code?

buttonView = [[UIButton alloc] init];

buttonView.translatesAutoresizingMaskIntoConstraints = NO;

[self.view addSubview:buttonView];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:buttonView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f]];

... etc

It's certainly better than the stress you'll have with UIView+Positioning or IB.




Apple's options for Auto Layout in code aren't the best. Check out some of the fantastic third party APIs available.

I'm the developer of UIView+AutoLayout, which is designed to provide the API that Apple should have in the first place (it's inspired heavily by the IB options): https://github.com/smileyborg/UIView-AutoLayout


I've used a similar one myself. Same name but different project: https://github.com/jrturton/UIView-Autolayout/blob/master/So...

Thank you for making this area of ios dev less painful. :)


Damn, I was just getting ready to write a comment recommending UIView+AutoLayout to steal some karma from iOS developers who are not using it yet.

Seriously though, thanks for this! It really makes working with AutoLayout so much easier.


Agreed, I've been using https://github.com/dkduck/FLKAutoLayout to simplify the constraint creation




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: