Skip to content

Commit

Permalink
Merge pull request #4 from angelos/text_alignment
Browse files Browse the repository at this point in the history
Allow button alignment
  • Loading branch information
Jimmy Arts authored Jun 14, 2016
2 parents 32dc909 + 8ddebb3 commit fc599c1
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 fc599c1

Please sign in to comment.