Added first/last baseline support
Showing
10 changed files
with
94 additions
and
1 deletions
@@ -45,7 +45,7 @@ static UIEdgeInsets const kPadding = {10, 10, 10, 10}; | @@ -45,7 +45,7 @@ static UIEdgeInsets const kPadding = {10, 10, 10, 10}; | ||
45 | }]; | 45 | }]; |
46 | 46 | ||
47 | [self.shortLabel makeConstraints:^(MASConstraintMaker *make) { | 47 | [self.shortLabel makeConstraints:^(MASConstraintMaker *make) { |
48 | - make.centerY.equalTo(self.longLabel.centerY); | 48 | + make.firstBaseline.equalTo(self.longLabel.centerY); |
49 | make.right.equalTo(self.right).insets(kPadding); | 49 | make.right.equalTo(self.right).insets(kPadding); |
50 | }]; | 50 | }]; |
51 | 51 |
@@ -127,6 +127,13 @@ | @@ -127,6 +127,13 @@ | ||
127 | - (MASConstraint *)centerY; | 127 | - (MASConstraint *)centerY; |
128 | - (MASConstraint *)baseline; | 128 | - (MASConstraint *)baseline; |
129 | 129 | ||
130 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
131 | + | ||
132 | +- (MASConstraint *)firstBaseline; | ||
133 | +- (MASConstraint *)lastBaseline; | ||
134 | + | ||
135 | +#endif | ||
136 | + | ||
130 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 137 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
131 | 138 | ||
132 | - (MASConstraint *)leftMargin; | 139 | - (MASConstraint *)leftMargin; |
@@ -208,6 +208,17 @@ | @@ -208,6 +208,17 @@ | ||
208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; | 208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; |
209 | } | 209 | } |
210 | 210 | ||
211 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
212 | + | ||
213 | +- (MASConstraint *)firstBaseline { | ||
214 | + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; | ||
215 | +} | ||
216 | +- (MASConstraint *)lastBaseline { | ||
217 | + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; | ||
218 | +} | ||
219 | + | ||
220 | +#endif | ||
221 | + | ||
211 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 222 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
212 | 223 | ||
213 | - (MASConstraint *)leftMargin { | 224 | - (MASConstraint *)leftMargin { |
@@ -22,6 +22,13 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { | @@ -22,6 +22,13 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { | ||
22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, | 22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, |
23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, | 23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, |
24 | 24 | ||
25 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
26 | + | ||
27 | + MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline, | ||
28 | + MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline, | ||
29 | + | ||
30 | +#endif | ||
31 | + | ||
25 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 32 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
26 | 33 | ||
27 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, | 34 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, |
@@ -60,6 +67,13 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { | @@ -60,6 +67,13 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) { | ||
60 | @property (nonatomic, strong, readonly) MASConstraint *centerY; | 67 | @property (nonatomic, strong, readonly) MASConstraint *centerY; |
61 | @property (nonatomic, strong, readonly) MASConstraint *baseline; | 68 | @property (nonatomic, strong, readonly) MASConstraint *baseline; |
62 | 69 | ||
70 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
71 | + | ||
72 | +@property (nonatomic, strong, readonly) MASConstraint *firstBaseline; | ||
73 | +@property (nonatomic, strong, readonly) MASConstraint *lastBaseline; | ||
74 | + | ||
75 | +#endif | ||
76 | + | ||
63 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 77 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
64 | 78 | ||
65 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin; | 79 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin; |
@@ -78,6 +78,9 @@ | @@ -78,6 +78,9 @@ | ||
78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading | 78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading |
79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX | 79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX |
80 | | MASAttributeCenterY | MASAttributeBaseline | 80 | | MASAttributeCenterY | MASAttributeBaseline |
81 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
82 | + | MASAttributeFirstBaseline | MASAttributeLastBaseline | ||
83 | +#endif | ||
81 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
82 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin | 85 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin |
83 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins | 86 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins |
@@ -101,6 +104,13 @@ | @@ -101,6 +104,13 @@ | ||
101 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; | 104 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; |
102 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; | 105 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; |
103 | 106 | ||
107 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
108 | + | ||
109 | + if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline]; | ||
110 | + if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline]; | ||
111 | + | ||
112 | +#endif | ||
113 | + | ||
104 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 114 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
105 | 115 | ||
106 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin]; | 116 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin]; |
@@ -182,6 +192,19 @@ | @@ -182,6 +192,19 @@ | ||
182 | }; | 192 | }; |
183 | } | 193 | } |
184 | 194 | ||
195 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
196 | + | ||
197 | +- (MASConstraint *)firstBaseline { | ||
198 | + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; | ||
199 | +} | ||
200 | + | ||
201 | +- (MASConstraint *)lastBaseline { | ||
202 | + return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; | ||
203 | +} | ||
204 | + | ||
205 | +#endif | ||
206 | + | ||
207 | + | ||
185 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 208 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
186 | 209 | ||
187 | - (MASConstraint *)leftMargin { | 210 | - (MASConstraint *)leftMargin { |
@@ -44,6 +44,11 @@ | @@ -44,6 +44,11 @@ | ||
44 | @(NSLayoutAttributeCenterY) : @"centerY", | 44 | @(NSLayoutAttributeCenterY) : @"centerY", |
45 | @(NSLayoutAttributeBaseline) : @"baseline", | 45 | @(NSLayoutAttributeBaseline) : @"baseline", |
46 | 46 | ||
47 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
48 | + @(NSLayoutAttributeFirstBaseline) : @"firstBaseline", | ||
49 | + @(NSLayoutAttributeLastBaseline) : @"lastBaseline", | ||
50 | +#endif | ||
51 | + | ||
47 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 52 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
48 | @(NSLayoutAttributeLeftMargin) : @"leftMargin", | 53 | @(NSLayoutAttributeLeftMargin) : @"leftMargin", |
49 | @(NSLayoutAttributeRightMargin) : @"rightMargin", | 54 | @(NSLayoutAttributeRightMargin) : @"rightMargin", |
@@ -32,6 +32,13 @@ | @@ -32,6 +32,13 @@ | ||
32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; | 32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; |
33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); | 33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); |
34 | 34 | ||
35 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
36 | + | ||
37 | +@property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline; | ||
38 | +@property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline; | ||
39 | + | ||
40 | +#endif | ||
41 | + | ||
35 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 42 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
36 | 43 | ||
37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; | 44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; |
@@ -87,6 +87,17 @@ | @@ -87,6 +87,17 @@ | ||
87 | }; | 87 | }; |
88 | } | 88 | } |
89 | 89 | ||
90 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
91 | + | ||
92 | +- (MASViewAttribute *)mas_firstBaseline { | ||
93 | + return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline]; | ||
94 | +} | ||
95 | +- (MASViewAttribute *)mas_lastBaseline { | ||
96 | + return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline]; | ||
97 | +} | ||
98 | + | ||
99 | +#endif | ||
100 | + | ||
90 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 101 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
91 | 102 | ||
92 | - (MASViewAttribute *)mas_leftMargin { | 103 | - (MASViewAttribute *)mas_leftMargin { |
@@ -29,6 +29,13 @@ | @@ -29,6 +29,13 @@ | ||
29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; | 29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; |
30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); | 30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); |
31 | 31 | ||
32 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
33 | + | ||
34 | +@property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline; | ||
35 | +@property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline; | ||
36 | + | ||
37 | +#endif | ||
38 | + | ||
32 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 39 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
33 | 40 | ||
34 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; | 41 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; |
@@ -67,6 +74,13 @@ MAS_ATTR_FORWARD(centerX); | @@ -67,6 +74,13 @@ MAS_ATTR_FORWARD(centerX); | ||
67 | MAS_ATTR_FORWARD(centerY); | 74 | MAS_ATTR_FORWARD(centerY); |
68 | MAS_ATTR_FORWARD(baseline); | 75 | MAS_ATTR_FORWARD(baseline); |
69 | 76 | ||
77 | +#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) | ||
78 | + | ||
79 | +MAS_ATTR_FORWARD(firstBaseline); | ||
80 | +MAS_ATTR_FORWARD(lastBaseline); | ||
81 | + | ||
82 | +#endif | ||
83 | + | ||
70 | #if TARGET_OS_IPHONE || TARGET_OS_TV | 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV |
71 | 85 | ||
72 | MAS_ATTR_FORWARD(leftMargin); | 86 | MAS_ATTR_FORWARD(leftMargin); |
-
Please register or login to post a comment