diff --git a/Pod/Classes/YAScrollSegmentControl.h b/Pod/Classes/YAScrollSegmentControl.h index d90a7f4..f904055 100644 --- a/Pod/Classes/YAScrollSegmentControl.h +++ b/Pod/Classes/YAScrollSegmentControl.h @@ -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; diff --git a/Pod/Classes/YAScrollSegmentControl.m b/Pod/Classes/YAScrollSegmentControl.m index 1039f0a..b01f98e 100644 --- a/Pod/Classes/YAScrollSegmentControl.m +++ b/Pod/Classes/YAScrollSegmentControl.m @@ -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; }