Skip to content

Instantly share code, notes, and snippets.

WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithHorizontalLayout:@[
label1,
[label2 setVStretches],
label3,]
setMargin:5]
setSpacing:5];
// Add three views with a flow layout.
// This layout will only apply to these three subviews.
WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithFlowLayout:@[
label,
imageView,
button,]
setMargin:5]
setSpacing:5];
// "Block-based" layouts are a catch-all mechanism for unusual layouts.
// In this example we randomly position a label within a WeView.
WeView *container = [[WeView alloc] init];
[container addSubview:label
withLayoutBlock:^(UIView *superview, UIView *subview) {
// Use random absolute positioning.
subview.frame = CGRectMake((arc4random() % 10) * 10,
(arc4random() % 10) * 20,
30, 40);
}];
// The most common way to use a stack layout is as a layout for a single subview.
WeView *container = [[WeView alloc] init];
[[[container addSubviewWithCustomLayout:label]
setMargin:5]
setSpacing:5];
// It can also be used to stack multiple views on top of each other.
WeView *container = [[WeView alloc] init];
[[[container addSubviewWithStackLayout:@[
label,
// Add three views with a vertical layout.
// This layout will only apply to these three subviews.
WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithVerticalLayout:@[
label,
imageView,
button,]
setMargin:5]
setSpacing:5];
// Add three views with a horizontal layout.
// This layout will only apply to these three subviews.
WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithHorizontalLayout:@[
label,
imageView,
button,]
setMargin:5]
setSpacing:5];
WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithHorizontalLayout:@[
[label setHStretches], // Indicates that this view should be stretched horizontally.
[imageView setHStretchWeight:2.f], // Indicates that this view be stretched horizontally with a specific weight.
button,]]
setMargin:5]
setSpacing:5];
WeView *container = [[WeView alloc] init];
[[[container addSubviewsWithHorizontalLayout:@[
label,
imageView,
button,]
setMargin:5]
setSpacing:5];
WeView *container = [[WeView alloc] init];
[[[[[container addSubviewsWithHorizontalLayout:@[
label,
imageView,
button,]
setMargin:5]
setSpacing:5]
setHAlign:H_ALIGN_LEFT]
setVAlign:V_ALIGN_TOP];
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.