Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加两处分割线的左右间距逻辑 #329

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BRPickerView/Core/BRPickerAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ - (UIView *)titleBarView {
_titleBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
if (!self.pickerStyle.hiddenTitleLine) {
// 设置标题栏底部分割线
UIView *titleLineView = [[UIView alloc]initWithFrame:CGRectMake(0, _titleBarView.frame.size.height - 0.5f, _titleBarView.frame.size.width, 0.5f)];
UIView *titleLineView = [[UIView alloc]initWithFrame:CGRectMake(self.pickerStyle.titleLineLeftSpace, _titleBarView.frame.size.height - self.pickerStyle.titleLineHeight, _titleBarView.frame.size.width - self.pickerStyle.titleLineLeftSpace - self.pickerStyle.titleLineRightSpace, self.pickerStyle.titleLineHeight)];
titleLineView.backgroundColor = self.pickerStyle.titleLineColor;
titleLineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[_titleBarView addSubview:titleLineView];
Expand Down
15 changes: 15 additions & 0 deletions BRPickerView/Core/BRPickerStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ typedef NS_ENUM(NSInteger, BRBorderStyle) {
/** 设置 titleBarView 标题栏底部分割线颜色 */
@property (nullable, nonatomic, strong) UIColor *titleLineColor;

/** 设置 titleBarView 标题栏底部分割线左边间距 */
@property (nonatomic, assign) CGFloat titleLineLeftSpace;

/** 设置 titleBarView 标题栏底部分割线左边间距 */
@property (nonatomic, assign) CGFloat titleLineRightSpace;

/** 设置 titleBarView 标题栏底部分割线高度 */
@property (nonatomic, assign) CGFloat titleLineHeight;

/** 隐藏 titleBarView 标题栏底部分割线,默认为 NO */
@property (nonatomic, assign) BOOL hiddenTitleLine;

Expand Down Expand Up @@ -169,6 +178,12 @@ typedef NS_ENUM(NSInteger, BRBorderStyle) {
/** 设置 picker 中间两条分割线的高度。暂不支持日期选择器前4种类型 */
@property (nonatomic, assign) CGFloat separatorHeight;

/** 设置 picker 中间两条分割线的左侧间距。暂不支持日期选择器前4种类型 */
@property (nonatomic, assign) CGFloat separatorLeftSpace;

/** 设置 picker 中间两条分割线的右侧间距。暂不支持日期选择器前4种类型 */
@property (nonatomic, assign) CGFloat separatorRightSpace;

/** 设置 picker 文本的颜色。暂不支持日期选择器前4种类型 */
@property (nullable, nonatomic, strong) UIColor *pickerTextColor;

Expand Down
25 changes: 23 additions & 2 deletions BRPickerView/Core/BRPickerStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ - (UIColor *)titleLineColor {
return _titleLineColor;
}

- (CGFloat)titleLineHeight {
if (_titleLineHeight <= 0) {
return 0.5f;
}
return _titleLineHeight;
}

- (CGFloat)titleLineLeftSpace{
if (_titleLineLeftSpace <= 0) {
return 0.0f;
}
return _titleLineLeftSpace;
}

- (CGFloat)titleLineRightSpace{
if (_titleLineRightSpace <= 0) {
return 0.0f;
}
return _titleLineRightSpace;
}

- (UIColor *)cancelColor {
if (!_cancelColor) {
_cancelColor = [UIColor clearColor];
Expand Down Expand Up @@ -465,7 +486,7 @@ - (void)setPickerAllSubViewsStyle:(UIView *)view {
#pragma mark - 添加选择器中间行上下两条分割线(iOS14之后系统默认去掉,需要手动添加)
- (void)addSeparatorLineView:(UIView *)pickerView {
if ([UIDevice currentDevice].systemVersion.doubleValue >= 14.0) {
UIView *topLineView = [[UIView alloc]initWithFrame:CGRectMake(0, pickerView.bounds.size.height / 2 - self.rowHeight / 2, pickerView.bounds.size.width, 0.5f)];
UIView *topLineView = [[UIView alloc]initWithFrame:CGRectMake(self.separatorLeftSpace, pickerView.bounds.size.height / 2 - self.rowHeight / 2, pickerView.bounds.size.width - self.separatorLeftSpace - self.separatorRightSpace, 0.5f)];
topLineView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
topLineView.backgroundColor = self.separatorColor;
// 设置分割线高度
Expand All @@ -476,7 +497,7 @@ - (void)addSeparatorLineView:(UIView *)pickerView {
}
[pickerView addSubview:topLineView];

UIView *bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(0, pickerView.bounds.size.height / 2 + self.rowHeight / 2, pickerView.bounds.size.width, 0.5f)];
UIView *bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(self.separatorLeftSpace, pickerView.bounds.size.height / 2 + self.rowHeight / 2, pickerView.bounds.size.width - self.separatorLeftSpace - self.separatorRightSpace, 0.5f)];
bottomLineView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
bottomLineView.backgroundColor = self.separatorColor;
// 设置分割线高度
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ - (void)handlerTextFieldSelect:(UITextField *)textField {
} else {
customStyle.pickerColor = BR_RGB_HEX(0xf2f2f7, 1.0f);
}
customStyle.separatorColor = [UIColor clearColor];
customStyle.separatorColor = [UIColor redColor];
customStyle.titleLineHeight = 1;
customStyle.titleLineLeftSpace = 20;
customStyle.titleLineRightSpace = 20;
customStyle.separatorLeftSpace = 20;
customStyle.separatorRightSpace = 20;
textPickerView.pickerStyle = customStyle;

[textPickerView show];
Expand Down