Skip to content

Commit e5a7a09

Browse files
committed
Autolayout on pages from Xib added
1 parent c3e0ff0 commit e5a7a09

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

EAIntroView/EAIntroPage.m

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ + (instancetype)pageWithCustomViewFromNibNamed:(NSString *)nibName {
5757
+ (instancetype)pageWithCustomViewFromNibNamed:(NSString *)nibName bundle:(NSBundle*)aBundle {
5858
EAIntroPage *newPage = [[self alloc] init];
5959
newPage.customView = [[aBundle loadNibNamed:nibName owner:newPage options:nil] firstObject];
60+
[newPage.customView setTranslatesAutoresizingMaskIntoConstraints:NO];
6061
return newPage;
6162
}
6263

EAIntroView/EAIntroView.m

+9-3
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,17 @@ - (void)buildScrollView {
321321
- (UIView *)viewForPage:(EAIntroPage *)page atXIndex:(CGFloat)xIndex {
322322
UIView *pageView = [[UIView alloc] initWithFrame:CGRectMake(xIndex, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
323323

324+
pageView.accessibilityLabel = [NSString stringWithFormat:@"intro_page_%lu",(unsigned long)[self.pages indexOfObject:page]];
325+
324326
if(page.customView) {
325-
page.customView.frame = pageView.bounds;
326327
[pageView addSubview:page.customView];
328+
329+
NSMutableArray *constraints = @[].mutableCopy;
330+
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[customView]-|" options:0 metrics:nil views:@{@"customView": page.customView}]];
331+
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[customView]-|" options:0 metrics:nil views:@{@"customView": page.customView}]];
332+
333+
[pageView addConstraints:constraints];
334+
327335
return pageView;
328336
}
329337

@@ -391,8 +399,6 @@ - (UIView *)viewForPage:(EAIntroPage *)page atXIndex:(CGFloat)xIndex {
391399
}
392400
}
393401

394-
pageView.accessibilityLabel = [NSString stringWithFormat:@"intro_page_%lu",(unsigned long)[self.pages indexOfObject:page]];
395-
396402
if(page.alpha < 1.f || !page.bgImage) {
397403
self.backgroundColor = [UIColor clearColor];
398404
}

0 commit comments

Comments
 (0)