Skip to content

Commit

Permalink
Introduced an alignment property, that flushes the buttons to one sid…
Browse files Browse the repository at this point in the history
…e if there is too much room.
  • Loading branch information
angelos committed Jun 10, 2016
1 parent 32dc909 commit 8ddebb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Pod/Classes/YAScrollSegmentControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ IB_DESIGNABLE
@property (nonatomic, strong) IBInspectable UIColor *buttonColor;
@property (nonatomic, strong) IBInspectable UIColor *buttonHighlightColor;
@property (nonatomic, strong) IBInspectable UIColor *buttonSelectedColor;
@property (nonatomic, assign) NSTextAlignment buttonAlignment;

@property (nonatomic, assign) NSInteger selectedIndex;

Expand Down
12 changes: 11 additions & 1 deletion Pod/Classes/YAScrollSegmentControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,17 @@ - (void)setButtons:(NSArray *)buttons
self.scrollView.contentSize = CGSizeMake(x, self.frame.size.height);

if (x <= self.frame.size.width) {
self.scrollView.contentInset = UIEdgeInsetsMake(0, (self.frame.size.width - x) / 2, 0, 0);
CGFloat padding = (self.frame.size.width - x) / 2;
if (self.buttonAlignment == NSTextAlignmentRight) {
self.scrollView.contentInset = UIEdgeInsetsMake(0, padding * 2, 0, 0);
}
else if (self.buttonAlignment == NSTextAlignmentCenter || self.buttonAlignment == NSTextAlignmentJustified) {
self.scrollView.contentInset = UIEdgeInsetsMake(0, padding, 0, padding);
}
else {
// Either left or natural
self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, padding * 2);
}
} else {
self.scrollView.contentInset = UIEdgeInsetsZero;
}
Expand Down

0 comments on commit 8ddebb3

Please sign in to comment.