Hacker News new | ask | show | jobs
by msoad 3752 days ago
There is also SnapKit which I really like:

https://github.com/SnapKit/SnapKit

        box.snp_makeConstraints { (make) -> Void in
           make.width.height.equalTo(50)
           make.center.equalTo(self.view)
        }
5 comments

And Masonry, if you're still on Obj-C (like me):

https://github.com/SnapKit/Masonry

    [box mas_makeConstraints:^(MASConstraintMaker* make) {
        make.width.height.equalTo(50);
        make.center.equalTo(self.view);    
    }];
And cartography, which is my preference:

https://github.com/robb/Cartography

    constrain(button1, button2) { button1, button2 in
        button1.right == button2.left - 12
    }
Or use NSLayoutAnchor, which was added in iOS 9 and OS X 10.10;

    [box.widthAnchor constraintEqualToConstant:50].active = YES;
    [box.centerAnchor constrantEqualToAnchor:self.view.centerAnchor].active = YES;
Or while we're sharing, here's mine in Obj-C++ (although I never managed to extract it into a separate package):

https://github.com/viewfinderco/viewfinder/blob/master/clien...

    [self addConstraints:box.anchorWidth == 50];
    [self addConstraints:box.anchorHeight == 50];
    [self addConstraints:box.anchorCenterX == self.view.anchorCenterX];
    [self addConstraints:box.anchorCenterY == self.view.anchorCenterY];
Came here to say the same thing. I've abandoned storyboards and nibs in favor of SnapKit and it hasn't let me down so far. It's one of the better libraries I've used on OS X and iOS.