Skip to content

Commit

Permalink
增加iOS13 Dark样式适配, 默认样式兼容Dark样式, 增加`.LeeUserInterfaceStyle(UIUserInter…
Browse files Browse the repository at this point in the history
…faceStyleUnspecified)`方法强制样式类型.
  • Loading branch information
lixiang1994 committed Sep 30, 2019
1 parent b7d922b commit c7a160c
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 18 deletions.
3 changes: 3 additions & 0 deletions LEEAlert/LEEAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ NS_ASSUME_NONNULL_BEGIN
/** 设置 状态栏样式 -> 格式: .LeeStatusBarStyle(UIStatusBarStyleDefault) */
@property (nonatomic , copy , readonly ) LEEConfigToStatusBarStyle LeeStatusBarStyle;

/** 设置 系统界面样式 -> 格式: .LeeUserInterfaceStyle(UIUserInterfaceStyleUnspecified) */
@property (nonatomic , copy , readonly ) LEEConfigToUserInterfaceStyle LeeUserInterfaceStyle API_AVAILABLE(ios(13.0), tvos(13.0));


/** 显示 -> 格式: .LeeShow() */
@property (nonatomic , copy , readonly ) LEEConfig LeeShow;
Expand Down
172 changes: 156 additions & 16 deletions LEEAlert/LEEAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ @interface LEEBaseConfigModel ()
@property (nonatomic , assign ) UIStatusBarStyle modelStatusBarStyle;
@property (nonatomic , assign ) UIBlurEffectStyle modelBackgroundBlurEffectStyle;
@property (nonatomic , assign ) UIInterfaceOrientationMask modelSupportedInterfaceOrientations;
@property (nonatomic , assign ) UIUserInterfaceStyle modelUserInterfaceStyle API_AVAILABLE(ios(13.0), tvos(13.0));

@property (nonatomic , strong ) UIColor *modelActionSheetBackgroundColor;
@property (nonatomic , strong ) UIColor *modelActionSheetCancelActionSpaceColor;
Expand Down Expand Up @@ -133,7 +134,12 @@ - (instancetype)init
_modelActionSheetBottomMargin = 10.0f; //默认actionsheet距离屏幕底部距离

_modelShadowColor = [UIColor blackColor]; //默认阴影颜色
_modelHeaderColor = [UIColor whiteColor]; //默认颜色
if (@available(iOS 13.0, *)) {
_modelHeaderColor = [UIColor tertiarySystemBackgroundColor]; //默认颜色

} else {
_modelHeaderColor = [UIColor whiteColor]; //默认颜色
}
_modelBackgroundColor = [UIColor blackColor]; //默认背景半透明颜色

_modelIsClickBackgroundClose = NO; //默认点击背景不关闭
Expand All @@ -149,6 +155,10 @@ - (instancetype)init
_modelBackgroundBlurEffectStyle = UIBlurEffectStyleDark; //默认模糊效果类型Dark
_modelSupportedInterfaceOrientations = UIInterfaceOrientationMaskAll; //默认支持所有方向

if (@available(iOS 13.0, *)) {
_modelUserInterfaceStyle = UIUserInterfaceStyleUnspecified; //默认支持全部样式
}

__weak typeof(self) weakSelf = self;

_modelOpenAnimationConfigBlock = ^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {
Expand Down Expand Up @@ -274,7 +284,7 @@ - (LEEConfigToStringAndBlock)LeeDestructiveAction{

action.title = title;

action.titleColor = [UIColor redColor];
action.titleColor = [UIColor systemRedColor];

action.clickBlock = block;
});
Expand Down Expand Up @@ -750,6 +760,16 @@ - (LEEConfigToStatusBarStyle)LeeStatusBarStyle{

}

- (LEEConfigToUserInterfaceStyle)LeeUserInterfaceStyle {

return ^(UIUserInterfaceStyle style){

self.modelUserInterfaceStyle = style;

return self;
};
}


- (LEEConfig)LeeShow{

Expand Down Expand Up @@ -863,6 +883,54 @@ - (LEEConfigToBool)LeeAvoidKeyboard{

@end

@implementation LEEBaseConfigModel (ActionSheet)

- (LEEConfigToFloat)LeeActionSheetCancelActionSpaceWidth{

return ^(CGFloat number){

self.modelActionSheetCancelActionSpaceWidth = number;

return self;
};

}

- (LEEConfigToColor)LeeActionSheetCancelActionSpaceColor{

return ^(UIColor *color){

self.modelActionSheetCancelActionSpaceColor = color;

return self;
};

}

- (LEEConfigToFloat)LeeActionSheetBottomMargin{

return ^(CGFloat number){

self.modelActionSheetBottomMargin = number;

return self;
};

}

- (LEEConfigToColor)LeeActionSheetBackgroundColor{

return ^(UIColor *color){

self.modelActionSheetBackgroundColor = color;

return self;
};

}

@end

@interface LEEAlert ()

@property (nonatomic , strong ) UIWindow *mainWindow;
Expand Down Expand Up @@ -1157,6 +1225,12 @@ @interface LEEActionButton ()

@implementation LEEActionButton

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
/// 刷新Action设置
self.action = self.action;
}

+ (LEEActionButton *)button{

return [LEEActionButton buttonWithType:UIButtonTypeCustom];;
Expand Down Expand Up @@ -1283,22 +1357,22 @@ - (void)layoutSubviews{
}

- (void)addTopBorder{

[self removeTopBorder];
[self.layer addSublayer:self.topLayer];
}

- (void)addBottomBorder{

[self removeBottomBorder];
[self.layer addSublayer:self.bottomLayer];
}

- (void)addLeftBorder{

[self removeLeftBorder];
[self.layer addSublayer:self.leftLayer];
}

- (void)addRightBorder{

[self removeRightBorder];
[self.layer addSublayer:self.rightLayer];
}

Expand Down Expand Up @@ -2154,7 +2228,12 @@ - (void)configAlert{

label.font = [UIFont boldSystemFontOfSize:18.0f];

label.textColor = [UIColor blackColor];
if (@available(iOS 13.0, *)) {
label.textColor = [UIColor labelColor];

} else {
label.textColor = [UIColor blackColor];
}

label.numberOfLines = 0;

Expand Down Expand Up @@ -2183,7 +2262,12 @@ - (void)configAlert{

label.font = [UIFont systemFontOfSize:14.0f];

label.textColor = [UIColor blackColor];
if (@available(iOS 13.0, *)) {
label.textColor = [UIColor labelColor];

} else {
label.textColor = [UIColor blackColor];
}

label.numberOfLines = 0;

Expand Down Expand Up @@ -2257,13 +2341,34 @@ - (void)configAlert{

if (!action.title) action.title = @"按钮";

if (!action.titleColor) action.titleColor = [UIColor colorWithRed:21/255.0f green:123/255.0f blue:245/255.0f alpha:1.0f];
if (!action.titleColor) {
if (@available(iOS 13.0, *)) {
action.titleColor = [UIColor systemBlueColor];

} else {
action.titleColor = [UIColor colorWithRed:21/255.0f green:123/255.0f blue:245/255.0f alpha:1.0f];
}
}

if (!action.backgroundColor) action.backgroundColor = self.config.modelHeaderColor;

if (!action.backgroundHighlightColor) action.backgroundHighlightColor = action.backgroundHighlightColor = [UIColor colorWithWhite:0.97 alpha:1.0f];
if (!action.backgroundHighlightColor) {
if (@available(iOS 13.0, *)) {
action.backgroundHighlightColor = [UIColor systemGray6Color];

} else {
action.backgroundHighlightColor = [UIColor colorWithWhite:0.97 alpha:1.0f];
}
}

if (!action.borderColor) action.borderColor = [UIColor colorWithWhite:0.84 alpha:1.0f];
if (!action.borderColor) {
if (@available(iOS 13.0, *)) {
action.borderColor = [UIColor systemGray3Color];

} else {
action.borderColor = [UIColor colorWithWhite:0.84 alpha:1.0f];
}
}

if (!action.borderWidth) action.borderWidth = DEFAULTBORDERWIDTH;

Expand Down Expand Up @@ -2875,7 +2980,12 @@ - (void)configActionSheet{

label.font = [UIFont boldSystemFontOfSize:16.0f];

label.textColor = [UIColor darkGrayColor];
if (@available(iOS 13.0, *)) {
label.textColor = [UIColor secondaryLabelColor];

} else {
label.textColor = [UIColor darkGrayColor];
}

label.numberOfLines = 0;

Expand Down Expand Up @@ -2904,7 +3014,12 @@ - (void)configActionSheet{

label.font = [UIFont systemFontOfSize:14.0f];

label.textColor = [UIColor grayColor];
if (@available(iOS 13.0, *)) {
label.textColor = [UIColor tertiaryLabelColor];

} else {
label.textColor = [UIColor grayColor];
}

label.numberOfLines = 0;

Expand Down Expand Up @@ -2957,13 +3072,34 @@ - (void)configActionSheet{

if (!action.title) action.title = @"按钮";

if (!action.titleColor) action.titleColor = [UIColor colorWithRed:21/255.0f green:123/255.0f blue:245/255.0f alpha:1.0f];
if (!action.titleColor) {
if (@available(iOS 13.0, *)) {
action.titleColor = [UIColor systemBlueColor];

} else {
action.titleColor = [UIColor colorWithRed:21/255.0f green:123/255.0f blue:245/255.0f alpha:1.0f];
}
}

if (!action.backgroundColor) action.backgroundColor = self.config.modelHeaderColor;

if (!action.backgroundHighlightColor) action.backgroundHighlightColor = action.backgroundHighlightColor = [UIColor colorWithWhite:0.97 alpha:1.0f];
if (!action.backgroundHighlightColor) {
if (@available(iOS 13.0, *)) {
action.backgroundHighlightColor = [UIColor systemGray6Color];

} else {
action.backgroundHighlightColor = [UIColor colorWithWhite:0.97 alpha:1.0f];
}
}

if (!action.borderColor) action.borderColor = [UIColor colorWithWhite:0.86 alpha:1.0f];
if (!action.borderColor) {
if (@available(iOS 13.0, *)) {
action.borderColor = [UIColor systemGray3Color];

} else {
action.borderColor = [UIColor colorWithWhite:0.84 alpha:1.0f];
}
}

if (!action.borderWidth) action.borderWidth = DEFAULTBORDERWIDTH;

Expand Down Expand Up @@ -3403,6 +3539,10 @@ - (void)show{

[LEEAlert shareManager].leeWindow.hidden = NO;

if (@available(iOS 13.0, *)) {
[LEEAlert shareManager].leeWindow.overrideUserInterfaceStyle = self.config.modelUserInterfaceStyle;
}

[[LEEAlert shareManager].leeWindow makeKeyAndVisible];

__weak typeof(self) weakSelf = self;
Expand Down
2 changes: 2 additions & 0 deletions LEEAlert/LEEAlertHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToBlockReturnBool)(BOOL(^block)
typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToBlockIntegerReturnBool)(BOOL(^block)(NSInteger index));
typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToBlockAndBlock)(void(^)(void (^animatingBlock)(void) , void (^animatedBlock)(void)));
typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToStatusBarStyle)(UIStatusBarStyle style);
API_AVAILABLE(ios(13.0))
typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToUserInterfaceStyle)(UIUserInterfaceStyle style);
NS_ASSUME_NONNULL_END

#endif /* LEEAlertHelper_h */
7 changes: 7 additions & 0 deletions LEEAlertDemo/LEEAlertDemo/ActionSheetTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ - (void)demo:(NSInteger)index{
};
})
.LeeHeaderColor(blueColor)
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -625,6 +626,7 @@ - (void)demo:(NSInteger)index{
return CGRectGetWidth([[UIScreen mainScreen] bounds]);
})
.LeeActionSheetBackgroundColor([UIColor whiteColor]) // 通过设置背景颜色来填充底部间隙
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -658,6 +660,7 @@ - (void)demo:(NSInteger)index{

action.titleColor = [UIColor grayColor];
})
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -697,6 +700,7 @@ - (void)demo:(NSInteger)index{

return type == LEEScreenOrientationTypeHorizontal ? CGRectGetHeight([[UIScreen mainScreen] bounds]) : CGRectGetWidth([[UIScreen mainScreen] bounds]);
})
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -751,6 +755,7 @@ - (void)demo:(NSInteger)index{

return CGRectGetWidth([[UIScreen mainScreen] bounds]);
})
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -836,6 +841,7 @@ - (void)demo:(NSInteger)index{

return CGRectGetWidth([[UIScreen mainScreen] bounds]);
})
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down Expand Up @@ -925,6 +931,7 @@ - (void)demo:(NSInteger)index{
}];

})
.LeeUserInterfaceStyle(UIUserInterfaceStyleLight)
.LeeShow();
}
break;
Expand Down
Loading

0 comments on commit c7a160c

Please sign in to comment.