-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathNSLayoutConstraint+SimpleFormatLanguage.h
80 lines (57 loc) · 3.05 KB
/
NSLayoutConstraint+SimpleFormatLanguage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// NSLayoutConstraint+NSLayoutConstraint_SimpleFormatLanguage.h
// AutoLayoutFun
//
// Created by Ethan Vaughan on 11/28/13.
// Copyright (c) 2013 Ethan James Vaughan. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NSLayoutConstraint (SimpleFormatLanguage)
/**
An intuitive and powerful replacement for Apple's Visual Format Language. A constraint is specified using the following syntax: view1.attribute relation multiplier * view2.attribute + constant @ priority.
@code
UIView *superview = ...;
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.translatesAutoresizingMaskIntoConstraints = NO;
[superview addSubview:v];
[superview addConstraint:
[NSLayoutConstraint
constraintWithSimpleFormat:
@"v.centerX = superview.centerX"
metrics:nil
views:
NSDictionaryOfVariableBindings(v, superview)]];
@endcode
@see https://github.com/ejvaughan/SimpleFormatLanguage for more information.
@param format The simple format string containing the constraint description. Raises an @c NSInvalidArgumentException if @c format is nil.
@param metrics A dictionary of constants that replace named values in @c format. The keys are the placeholder names, and the values are NSNumber objects.
@param views A dictionary of views that appear in @c format. The keys are the names of the views in the format string, and the values are the views themselves. Raises an @c NSInvalidArgumentException if @c views is nil.
@return A constraint, or nil if there was an error parsing the format string
*/
+ (NSLayoutConstraint *)constraintWithSimpleFormat:(NSString *)format metrics:(NSDictionary *)metrics views:(NSDictionary *)views;
/**
Create multiple constraints from an array of simple format language constraints. A constraint is specified using the following syntax: view1.attribute relation multiplier * view2.attribute + constant @ priority.
@code
UIView *superview = ...;
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.translatesAutoresizingMaskIntoConstraints = NO;
[superview addSubview:v];
[superview addConstraints:
[NSLayoutConstraint
constraintsWithSimpleFormat:
@[ @"v.width = 100",
@"v.height = v.width",
@"v.centerX = superview.centerX",
@"v.centerY = superview.centerY" ]
metrics:nil
views:
NSDictionaryOfVariableBindings(v, superview)]];
@endcode
@see https://github.com/ejvaughan/SimpleFormatLanguage for more information.
@param formattedConstraints An array of simple format language constraints.
@param metrics A dictionary of constants that replace named values in the format strings. The keys are the placeholder names, and the values are NSNumber objects.
@param views A dictionary of views that appear in the format strings. The keys are the names of the views in the format strings, and the values are the views themselves.
@return An array of constraints
*/
+ (NSArray *)constraintsWithSimpleFormat:(NSArray *)formattedConstraints metrics:(NSDictionary *)metrics views:(NSDictionary *)views;
@end