Skip to content

Commit ce16951

Browse files
committed
Update UIView+AutoLayout library to latest version (v1.2)
1 parent 5e06d3d commit ce16951

3 files changed

Lines changed: 432 additions & 109 deletions

File tree

TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ - (void)updateConstraints
7979
// See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188
8080
// self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);
8181

82-
[self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
82+
[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
83+
[self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
84+
}];
8385
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
8486
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
8587
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
@@ -91,7 +93,9 @@ - (void)updateConstraints
9193
// See https://github.com/smileyborg/TableViewCellWithAutoLayout/issues/3 for more info.
9294
[self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets relation:NSLayoutRelationGreaterThanOrEqual];
9395

94-
[self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
96+
[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
97+
[self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
98+
}];
9599
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
96100
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
97101
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// UIView+AutoLayout.h
3-
// v1.0.0
3+
// v1.2.0
44
// https://github.com/smileyborg/UIView-AutoLayout
55
//
66
// Copyright (c) 2012 Richard Turton
@@ -29,24 +29,26 @@
2929

3030
#import <UIKit/UIKit.h>
3131

32+
#pragma mark ALAttributes
33+
3234
typedef NS_ENUM(NSInteger, ALEdge) {
33-
ALEdgeTop = 0, // the top edge of the view
34-
ALEdgeLeft, // the left edge of the view
35-
ALEdgeBottom, // the bottom edge of the view
36-
ALEdgeRight, // the right edge of the view
37-
ALEdgeLeading, // the leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic)
38-
ALEdgeTrailing // the trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic)
35+
ALEdgeLeft = NSLayoutAttributeLeft, // the left edge of the view
36+
ALEdgeRight = NSLayoutAttributeRight, // the right edge of the view
37+
ALEdgeTop = NSLayoutAttributeTop, // the top edge of the view
38+
ALEdgeBottom = NSLayoutAttributeBottom, // the bottom edge of the view
39+
ALEdgeLeading = NSLayoutAttributeLeading, // the leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic)
40+
ALEdgeTrailing = NSLayoutAttributeTrailing // the trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic)
3941
};
4042

41-
typedef NS_ENUM(NSInteger, ALAxis) {
42-
ALAxisHorizontal = 0, // a horizontal line through the center of the view
43-
ALAxisVertical, // a vertical line through the center of the view
44-
ALAxisBaseline // a horizontal line at the text baseline (not applicable to all views)
43+
typedef NS_ENUM(NSInteger, ALDimension) {
44+
ALDimensionWidth = NSLayoutAttributeWidth, // the width of the view
45+
ALDimensionHeight = NSLayoutAttributeHeight // the height of the view
4546
};
4647

47-
typedef NS_ENUM(NSInteger, ALDimension) {
48-
ALDimensionWidth = 0, // the width of the view
49-
ALDimensionHeight // the height of the view
48+
typedef NS_ENUM(NSInteger, ALAxis) {
49+
ALAxisVertical = NSLayoutAttributeCenterX, // a vertical line through the center of the view
50+
ALAxisHorizontal = NSLayoutAttributeCenterY, // a horizontal line through the center of the view
51+
ALAxisBaseline = NSLayoutAttributeBaseline // a horizontal line at the text baseline (not applicable to all views)
5052
};
5153

5254
typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UIView+AutoLayout category API
@@ -69,13 +71,15 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
6971
- (instancetype)initForAutoLayout;
7072

7173

72-
#pragma mark Auto Layout Convenience Methods
74+
#pragma mark Set Constraint Priority
7375

7476
/** Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout category API within the given constraints block.
7577
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! */
7678
+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
7779

7880

81+
#pragma mark Remove Constraints
82+
7983
/** Removes the given constraint from the view it has been added to. */
8084
+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint;
8185

@@ -103,19 +107,16 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
103107
- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints;
104108

105109

110+
#pragma mark Center in Superview
111+
106112
/** Centers the view in its superview. */
107113
- (NSArray *)autoCenterInSuperview;
108114

109-
/** Centers the view along the given axis (horizontal or vertical) within its superview. */
110-
- (NSLayoutConstraint *)autoCenterInSuperviewAlongAxis:(ALAxis)axis;
111-
112-
113-
/** Pins the given center axis of the view to a fixed position (X or Y value, depending on axis) in the superview. */
114-
- (NSLayoutConstraint *)autoPinCenterAxis:(ALAxis)axis toPositionInSuperview:(CGFloat)value;
115+
/** Aligns the view to the same axis of its superview. */
116+
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
115117

116-
/** Pins the given edge of the view to a fixed position (X or Y value, depending on edge) in the superview. */
117-
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toPositionInSuperview:(CGFloat)value;
118118

119+
#pragma mark Pin Edges to Superview
119120

120121
/** Pins the given edge of the view to the same edge of the superview with an inset. */
121122
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset;
@@ -127,6 +128,8 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
127128
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets;
128129

129130

131+
#pragma mark Pin Edges
132+
130133
/** Pins an edge of the view to a given edge of another view. */
131134
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView;
132135

@@ -137,13 +140,17 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
137140
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
138141

139142

143+
#pragma mark Align Axes
144+
140145
/** Aligns an axis of the view to the same axis of another view. */
141146
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView;
142147

143148
/** Aligns an axis of the view to the same axis of another view with an offset. */
144149
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset;
145150

146151

152+
#pragma mark Match Dimensions
153+
147154
/** Matches a dimension of the view to a given dimension of another view. */
148155
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView;
149156

@@ -160,6 +167,8 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
160167
- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
161168

162169

170+
#pragma mark Set Dimensions
171+
163172
/** Sets the view to a specific size. */
164173
- (NSArray *)autoSetDimensionsToSize:(CGSize)size;
165174

@@ -170,12 +179,59 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
170179
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation;
171180

172181

182+
#pragma mark Set Content Compression Resistance & Hugging
183+
184+
/** Sets the priority of content compression resistance for an axis.
185+
NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
186+
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis;
187+
188+
/** Sets the priority of content hugging for an axis.
189+
NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */
190+
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis;
191+
192+
193+
#pragma mark Constrain Any Attributes
194+
195+
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. */
196+
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView;
197+
198+
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. */
199+
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset;
200+
201+
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. */
202+
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
203+
204+
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. */
205+
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier;
206+
207+
/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. */
208+
- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
209+
210+
211+
#pragma mark Pin to Layout Guides
212+
173213
/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. */
174214
- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
175215

176216
/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. */
177217
- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset;
178218

219+
220+
#pragma mark Deprecated API Methods
221+
222+
/** DEPRECATED as of v1.1, will be removed at some point in the future. Use -[autoAlignAxisToSuperviewAxis:] instead.
223+
(This method has simply been renamed due to confusion. The replacement method works identically.)
224+
Centers the view along the given axis (horizontal or vertical) within its superview. */
225+
- (NSLayoutConstraint *)autoCenterInSuperviewAlongAxis:(ALAxis)axis __attribute__((deprecated));
226+
227+
/** DEPRECATED as of v1.1, will be removed at some point in the future. Use -[autoConstrainAttribute:toAttribute:ofView:withOffset:] instead.
228+
Pins the given center axis of the view to a fixed position (X or Y value, depending on axis) in the superview. */
229+
- (NSLayoutConstraint *)autoPinCenterAxis:(ALAxis)axis toPositionInSuperview:(CGFloat)value __attribute__((deprecated));
230+
231+
/** DEPRECATED as of v1.1, will be removed at some point in the future. Use -[autoPinEdgeToSuperviewEdge:withInset:] instead.
232+
Pins the given edge of the view to a fixed position (X or Y value, depending on edge) in the superview. */
233+
- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toPositionInSuperview:(CGFloat)value __attribute__((deprecated));
234+
179235
@end
180236

181237

@@ -186,6 +242,9 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
186242
*/
187243
@interface NSArray (AutoLayout)
188244

245+
246+
#pragma mark Constrain Multiple Views
247+
189248
/** Aligns views in this array to one another along a given edge. */
190249
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge;
191250

@@ -199,10 +258,12 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI
199258
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
200259

201260

202-
/** Distributes the views in this array equally along the selected axis. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
261+
#pragma mark Distribute Multiple Views
262+
263+
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
203264
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment;
204265

205-
/** Distributes the views in this array equally along the selected axis. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
266+
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
206267
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment;
207268

208269
@end

0 commit comments

Comments
 (0)