Skip to content

Instantly share code, notes, and snippets.

@3-n
Last active January 4, 2016 22:09
Show Gist options
  • Save 3-n/8686295 to your computer and use it in GitHub Desktop.
Save 3-n/8686295 to your computer and use it in GitHub Desktop.
Ad hoc grid with KeepLayout
GTButton *button0 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"top" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button1 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"1" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button2 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"2" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button3 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"3" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button4 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"4" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button5 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"5" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
GTButton *button6 = ({
GTButton *button = [[GTButton alloc] init];
[button setTitle:@"6" forState:UIControlStateNormal];
[self.view addSubview:button];
button;
});
NSArray *a1 = @[ button1, button2, button3 ];
NSArray *a2 = @[ button4, button5, button6 ];
NSArray *a = @[ button1, button2, button3, button4, button5, button6 ];
KeepValue x = KeepRequired(20);
a.keepAspectRatio.equal = KeepRequired(1);
[a keepSizesEqualWithPriority:KeepPriorityRequired];
[a1 keepHorizontalOffsets:x];
[a2 keepHorizontalOffsets:x];
[a1 keepHorizontallyAligned];
[a2 keepHorizontallyAligned];
button0.keepTopInset.equal = x;
button0.keepHorizontalInsets.equal = x;
button1.keepTopOffsetTo(button0).equal = x;
button1.keepLeftInset.equal = x;
button3.keepRightInset.equal = x;
button4.keepTopOffsetTo(button1).equal = x;
button4.keepLeftInset.equal = x;
button6.keepRightInset.equal = x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment