File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 77
88#import " ALMenuCollectionViewCell.h"
99
10+ #import " UIView+ALLayout.h"
11+
1012#import " ALMenuItem.h"
1113#import " ALUtils.h"
1214
@@ -37,10 +39,7 @@ - (void)setButton:(UIView<ALMenuItem> *)button
3739 else
3840 {
3941 [self .contentView addSubview: button];
40- [button.leadingAnchor constraintEqualToAnchor: self .contentView.leadingAnchor].active = YES ;
41- [button.topAnchor constraintEqualToAnchor: self .contentView.topAnchor].active = YES ;
42- [button.trailingAnchor constraintEqualToAnchor: self .contentView.trailingAnchor].active = YES ;
43- [button.bottomAnchor constraintEqualToAnchor: self .contentView.bottomAnchor].active = YES ;
42+ [button al_pinToSuperview ];
4443 }
4544
4645 _button = button;
Original file line number Diff line number Diff line change @@ -194,10 +194,7 @@ - (void)buildView
194194 [self .collectionView registerClass: [ALMenuCollectionViewCell class ] forCellWithReuseIdentifier: kCollectionViewCellReuseIdentifier ];
195195
196196 [self .containerView addSubview: self .collectionView];
197- [self .collectionView.leadingAnchor constraintEqualToAnchor: self .containerView.leadingAnchor].active = YES ;
198- [self .collectionView.trailingAnchor constraintEqualToAnchor: self .containerView.trailingAnchor].active = YES ;
199- [self .collectionView.topAnchor constraintEqualToAnchor: self .containerView.topAnchor].active = YES ;
200- [self .collectionView.bottomAnchor constraintEqualToAnchor: self .containerView.bottomAnchor].active = YES ;
197+ [self .collectionView al_pinToSuperview ];
201198
202199 self.containerViewWidthConstraint = [self .containerView.widthAnchor constraintEqualToConstant: self .collectionView.contentSize.width];
203200 self.containerViewWidthConstraint .active = YES ;
Original file line number Diff line number Diff line change 1313
1414- (void )al_adjustPositionForNewAnchorPoint : (CGPoint)anchorPoint ;
1515
16+ #pragma mark - Auto Layout
17+
18+ - (void )al_pinToSuperview ;
19+ - (void )al_pinToView : (UIView *)view ;
20+
1621@end
Original file line number Diff line number Diff line change @@ -30,4 +30,25 @@ - (void)al_adjustPositionForNewAnchorPoint:(CGPoint)anchorPoint
3030 self.layer .anchorPoint = anchorPoint;
3131}
3232
33+ #pragma mark - Auto Layout
34+
35+ - (void )al_pinToSuperview
36+ {
37+ [self al_pinToView: self .superview];
38+ }
39+
40+ - (void )al_pinToView : (UIView *)view
41+ {
42+ NSParameterAssert (view != nil );
43+
44+ // forgetting to set this is the bane of my professional career
45+ self.translatesAutoresizingMaskIntoConstraints = NO ;
46+
47+ // then constrain
48+ [self .leadingAnchor constraintEqualToAnchor: view.leadingAnchor].active = YES ;
49+ [self .trailingAnchor constraintEqualToAnchor: view.trailingAnchor].active = YES ;
50+ [self .topAnchor constraintEqualToAnchor: view.topAnchor].active = YES ;
51+ [self .bottomAnchor constraintEqualToAnchor: view.bottomAnchor].active = YES ;
52+ }
53+
3354@end
You can’t perform that action at this time.
0 commit comments