Skip to content

Commit

Permalink
为 QMUIConfigurationManager 的所有属性增加是否允许为 nil 的标志,并修复某些地方如果值为 nil 可能导致 …
Browse files Browse the repository at this point in the history
…crash,清理废弃的配置项
  • Loading branch information
MoLice committed Mar 30, 2017
1 parent 573ac12 commit 50c73b3
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 228 deletions.
14 changes: 1 addition & 13 deletions QMUIKit/UICommon/QMUIConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/*
* 定义宏,宏的值是通过QMUIConfigurationManager的单例来获取属性的值。
* 如果项目需要修改根据项目来修改某些宏的名字,请通过QMUIConfigurationManager来修改相应的属性,然后在项目启动的地方调用。
* @waining 如果需要增加一个宏,则需要定义一个新的QMUIConfigurationManager属性。(具体请联系zhoonchen/molicechen)
* @waining 如果需要增加一个宏,则需要定义一个新的QMUIConfigurationManager属性。
*/


Expand Down Expand Up @@ -56,10 +56,6 @@
#define UIControlHighlightedAlpha [QMUICMI controlHighlightedAlpha] // 一般control的Highlighted透明值
#define UIControlDisabledAlpha [QMUICMI controlDisabledAlpha] // 一般control的Disable透明值

#define SegmentTextTintColor [QMUICMI segmentTextTintColor] // segment的tintColor
#define SegmentTextSelectedTintColor [QMUICMI segmentTextSelectedTintColor] // segment选中态的tintColor
#define SegmentFontSize [QMUICMI segmentFontSize] // segment的字体大小

// 按钮
#pragma mark - UIButton
#define ButtonHighlightedAlpha [QMUICMI buttonHighlightedAlpha] // 按钮Highlighted状态的透明度
Expand All @@ -83,14 +79,6 @@
#define TextFieldTintColor [QMUICMI textFieldTintColor] // 全局UITextField、UITextView的tintColor
#define TextFieldTextInsets [QMUICMI textFieldTextInsets] // QMUITextField的内边距

#pragma mark - ActionSheet

#define ActionSheetButtonTintColor [QMUICMI actionSheetButtonTintColor]
#define ActionSheetButtonBackgroundColor [QMUICMI actionSheetButtonBackgroundColor]
#define ActionSheetButtonBackgroundColorHighlighted [QMUICMI actionSheetButtonBackgroundColorHighlighted]
#define ActionSheetButtonFont [QMUICMI actionSheetButtonFont]
#define ActionSheetButtonFontBold [QMUICMI actionSheetButtonFontBold]


#pragma mark - NavigationBar

Expand Down
276 changes: 132 additions & 144 deletions QMUIKit/UICommon/QMUIConfigurationManager.h

Large diffs are not rendered by default.

79 changes: 46 additions & 33 deletions QMUIKit/UICommon/QMUIConfigurationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,11 @@ - (void)initDefaultConfiguration {
self.testColorGreen = UIColorMakeWithRGBA(0, 255, 0, .3);
self.testColorBlue = UIColorMakeWithRGBA(0, 0, 255, .3);

#pragma mark - UIWindowLevel
self.windowLevelQMUIAlertView = UIWindowLevelAlert - 4.0;
self.windowLevelQMUIActionSheet = UIWindowLevelAlert - 4.0;
self.windowLevelQMUIMoreOperationController = UIWindowLevelStatusBar + 1;
self.windowLevelQMUIImagePreviewView = UIWindowLevelStatusBar + 1;

#pragma mark - UIControl

self.controlHighlightedAlpha = 0.5f;
self.controlDisabledAlpha = 0.5f;

self.segmentTextTintColor = self.blueColor;
self.segmentTextSelectedTintColor = self.whiteColor;
self.segmentFontSize = UIFontMake(13);

#pragma mark - UIButton

self.buttonHighlightedAlpha = self.controlHighlightedAlpha;
Expand All @@ -99,14 +89,6 @@ - (void)initDefaultConfiguration {
self.textFieldTintColor = UIColorBlue;
self.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7);

#pragma mark - ActionSheet

self.actionSheetButtonTintColor = self.blueColor;
self.actionSheetButtonBackgroundColor = UIColorMake(255, 255, 255);
self.actionSheetButtonBackgroundColorHighlighted = UIColorMake(235, 235, 235);
self.actionSheetButtonFont = UIFontMake(21);
self.actionSheetButtonFontBold = UIFontBoldMake(21);

#pragma mark - NavigationBar

self.navBarHighlightedAlpha = 0.2f;
Expand All @@ -115,10 +97,9 @@ - (void)initDefaultConfiguration {
self.navBarButtonFontBold = UIFontBoldMake(17);
self.navBarBackgroundImage = nil;
self.navBarShadowImage = nil;
self.navBarShadowImageColor = UIColorMake(178, 178, 178);
self.navBarBarTintColor = nil;
self.navBarTintColor = self.blackColor;
self.navBarTitleColor = nil;
self.navBarTitleColor = self.navBarTintColor;
self.navBarTitleFont = UIFontBoldMake(17);
self.navBarBackButtonTitlePositionAdjustment = UIOffsetZero;
self.navBarBackIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavBack size:CGSizeMake(12, 20) tintColor:self.navBarTintColor];
Expand Down Expand Up @@ -157,7 +138,7 @@ - (void)initDefaultConfiguration {
self.searchBarBottomBorderColor = UIColorMake(205, 208, 210);
self.searchBarBarTintColor = UIColorMake(247, 247, 247);
self.searchBarTintColor = self.blueColor;
self.searchBarTextColor = UIColorBlack;
self.searchBarTextColor = self.blackColor;
self.searchBarPlaceholderColor = self.placeholderColor;
self.searchBarSearchIconImage = nil;
self.searchBarClearIconImage = nil;
Expand All @@ -171,13 +152,18 @@ - (void)initDefaultConfiguration {
self.tableSectionIndexBackgroundColor = self.clearColor;
self.tableSectionIndexTrackingBackgroundColor = self.clearColor;
self.tableViewSeparatorColor = self.separatorColor;

self.tableViewCellNormalHeight = 44;
self.tableViewCellTitleLabelColor = self.blackColor;
self.tableViewCellDetailLabelColor = self.grayColor;
self.tableViewCellContentDefaultPaddingLeft = 15;
self.tableViewCellContentDefaultPaddingRight = 10;
self.tableViewCellBackgroundColor = self.whiteColor;
self.tableViewCellSelectedBackgroundColor = UIColorMake(232, 232, 232);
self.tableViewCellWarningBackgroundColor = self.yellowColor;
self.tableViewCellNormalHeight = 44;

self.tableViewCellDisclosureIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeDisclosureIndicator size:CGSizeMake(8, 13) tintColor:UIColorMakeWithRGBA(0, 0, 0, .2)];
self.tableViewCellCheckmarkImage = [UIImage qmui_imageWithShape:QMUIImageShapeCheckmark size:CGSizeMake(15, 12) tintColor:UIColorBlue];

self.tableViewSectionHeaderBackgroundColor = UIColorMake(244, 244, 244);
self.tableViewSectionFooterBackgroundColor = UIColorMake(244, 244, 244);
self.tableViewSectionHeaderFont = UIFontBoldMake(12);
Expand All @@ -198,10 +184,11 @@ - (void)initDefaultConfiguration {
self.tableViewGroupedSectionHeaderContentInset = UIEdgeInsetsMake(16, 15, 8, 15);
self.tableViewGroupedSectionFooterContentInset = UIEdgeInsetsMake(8, 15, 2, 15);

self.tableViewCellTitleLabelColor = self.blackColor;
self.tableViewCellDetailLabelColor = self.grayColor;
self.tableViewCellContentDefaultPaddingLeft = 15;
self.tableViewCellContentDefaultPaddingRight = 10;
#pragma mark - UIWindowLevel
self.windowLevelQMUIAlertView = UIWindowLevelAlert - 4.0;
self.windowLevelQMUIActionSheet = UIWindowLevelAlert - 4.0;
self.windowLevelQMUIMoreOperationController = UIWindowLevelStatusBar + 1;
self.windowLevelQMUIImagePreviewView = UIWindowLevelStatusBar + 1;

#pragma mark - Others

Expand All @@ -225,26 +212,52 @@ + (void)renderGlobalAppearances {
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
navigationBarAppearance.barTintColor = NavBarBarTintColor;
navigationBarAppearance.shadowImage = NavBarShadowImage;
navigationBarAppearance.titleTextAttributes = @{NSFontAttributeName: NavBarTitleFont, NSForegroundColorAttributeName: NavBarTitleColor};
[navigationBarAppearance setBackgroundImage:NavBarBackgroundImage forBarMetrics:UIBarMetricsDefault];

UIFont *navigationBarTitleFont = NavBarTitleFont;
UIColor *navigationBarTitleColor = NavBarTitleColor;
if (navigationBarTitleFont || navigationBarTitleColor) {
NSMutableDictionary<NSString *, id> *titleTextAttributes = [[NSMutableDictionary alloc] init];
if (navigationBarTitleFont) {
[titleTextAttributes setValue:navigationBarTitleFont forKey:NSFontAttributeName];
}
if (navigationBarTitleColor) {
[titleTextAttributes setValue:navigationBarTitleColor forKey:NSForegroundColorAttributeName];
}
navigationBarAppearance.titleTextAttributes = titleTextAttributes;
}

// UIToolBar
UIToolbar *toolBarAppearance = [UIToolbar appearance];
toolBarAppearance.barTintColor = ToolBarBarTintColor;
[toolBarAppearance setBackgroundImage:ToolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[toolBarAppearance setShadowImage:[UIImage qmui_imageWithColor:ToolBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0] forToolbarPosition:UIBarPositionAny];

UIColor *toolbarShadowImageColor = ToolBarShadowImageColor;
if (toolbarShadowImageColor) {
[toolBarAppearance setShadowImage:[UIImage qmui_imageWithColor:toolbarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0] forToolbarPosition:UIBarPositionAny];
}

// UITabBar
UITabBar *tabBarAppearance = [UITabBar appearance];
tabBarAppearance.barTintColor = TabBarBarTintColor;
tabBarAppearance.backgroundImage = TabBarBackgroundImage;
[tabBarAppearance setShadowImage:[UIImage qmui_imageWithColor:TabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]];

UIColor *tabBarShadowImageColor = TabBarShadowImageColor;
if (tabBarShadowImageColor) {
[tabBarAppearance setShadowImage:[UIImage qmui_imageWithColor:tabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]];
}

// UITabBarItem
UITabBarItem *tabBarItemAppearance = [UITabBarItem appearance];
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:TabBarItemTitleColor} forState:UIControlStateNormal];
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:TabBarItemTitleColorSelected} forState:UIControlStateSelected];

UIColor *tabBarItemTitleColor = TabBarItemTitleColor;
if (tabBarItemTitleColor) {
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:tabBarItemTitleColor} forState:UIControlStateNormal];
}

UIColor *tabBarItemTitleColorSelected = TabBarItemTitleColorSelected;
if (tabBarItemTitleColorSelected) {
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:tabBarItemTitleColorSelected} forState:UIControlStateSelected];
}
}

@end
11 changes: 0 additions & 11 deletions QMUIKit/UICommon/QMUIConfigurationTemplate.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ + (void)setupConfigurationTemplate {
//- QMUICMI.controlHighlightedAlpha = 0.5f; // UIControlHighlightedAlpha : 全局的highlighted alpha值
//- QMUICMI.controlDisabledAlpha = 0.5f; // UIControlDisabledAlpha : 全局的disabled alpha值

//- QMUICMI.segmentTextTintColor = UIColorBlue; // SegmentTextTintColor : segment的tintColor
//- QMUICMI.segmentTextSelectedTintColor = UIColorWhite; // SegmentTextSelectedTintColor : segment选中态的tintColor
//- QMUICMI.segmentFontSize = UIFontMake(13); // SegmentFontSize : segment的字体大小

#pragma mark - UIButton
//- QMUICMI.buttonHighlightedAlpha = UIControlHighlightedAlpha; // ButtonHighlightedAlpha : 按钮的highlighted alpha值
//- QMUICMI.buttonDisabledAlpha = UIControlDisabledAlpha; // ButtonDisabledAlpha : 按钮的disabled alpha值
Expand All @@ -92,13 +88,6 @@ + (void)setupConfigurationTemplate {
//- QMUICMI.textFieldTintColor = UIColorBlue; // TextFieldTintColor : 全局UITextField、UITextView的tintColor
//- QMUICMI.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7); // TextFieldTextInsets : QMUITextField的内边距

#pragma mark - ActionSheet
//- QMUICMI.actionSheetButtonTintColor = UIColorBlue; // ActionSheetButtonTintColor
//- QMUICMI.actionSheetButtonBackgroundColor = UIColorMake(255, 255, 255); // ActionSheetButtonBackgroundColor
//- QMUICMI.actionSheetButtonBackgroundColorHighlighted = UIColorMake(235, 235, 235); // ActionSheetButtonBackgroundColorHighlighted
//- QMUICMI.actionSheetButtonFont = UIFontMake(21); // ActionSheetButtonFont
//- QMUICMI.actionSheetButtonFontBold = UIFontBoldMake(21); // ActionSheetButtonFontBold

#pragma mark - NavigationBar

//- QMUICMI.navBarHighlightedAlpha = 0.2f; // NavBarHighlightedAlpha
Expand Down
16 changes: 11 additions & 5 deletions QMUIKit/UIKitExtensions/QMUIButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void)didInitialized {
self.adjustsImageTintColorAutomatically = NO;
self.tintColor = ButtonTintColor;
if (!self.adjustsTitleTintColorAutomatically) {
[self setTitleColor:ButtonTintColor forState:UIControlStateNormal];
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
}

// 默认接管highlighted和disabled的表现,去掉系统默认的表现
Expand Down Expand Up @@ -508,11 +508,15 @@ - (void)renderButtonStyle {
}
break;
case QMUINavigationButtonTypeBack: {
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
UIImage *backIndicatorImage = NavBarBackIndicatorImage;
if (!backIndicatorImage) {
QMUILog(@"NavBarBackIndicatorImage 为 nil,无法创建正确的 QMUINavigationButtonTypeBack 按钮");
return;
}
[self setImage:backIndicatorImage forState:UIControlStateNormal];
[self setImage:[backIndicatorImage qmui_imageWithAlpha:NavBarHighlightedAlpha] forState:UIControlStateHighlighted];
[self setImage:[backIndicatorImage qmui_imageWithAlpha:NavBarDisabledAlpha] forState:UIControlStateDisabled];
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
}
break;

Expand Down Expand Up @@ -748,9 +752,11 @@ - (void)renderButtonStyle {
}

+ (void)renderToolbarButtonAppearanceStyle {
// iOS7及以上默认使用系统自己的highlighted和disabled(及toolBar的tintColor),不使用ToolBarHighlightedAlpha和ToolBarDisabledAlpha
UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearanceWhenContainedIn:QMUINavigationController.class, nil];
[barButtonItemAppearance setTitleTextAttributes:@{NSFontAttributeName: ToolBarButtonFont} forState:UIControlStateNormal];
UIFont *titleFont = ToolBarButtonFont;
if (titleFont) {
UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearanceWhenContainedIn:QMUINavigationController.class, nil];
[barButtonItemAppearance setTitleTextAttributes:@{NSFontAttributeName: titleFont} forState:UIControlStateNormal];
}
}

+ (UIBarButtonItem *)barButtonItemWithToolbarButton:(QMUIToolbarButton *)button target:(id)target action:(SEL)selector {
Expand Down
2 changes: 1 addition & 1 deletion QMUIKit/UIKitExtensions/QMUISearchController.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ - (void)showEmptyView {
[super showEmptyView];

// 格式化样式,以适应当前项目的需求
self.emptyView.backgroundColor = TableViewBackgroundColor;
self.emptyView.backgroundColor = TableViewBackgroundColor ?: UIColorWhite;
if ([self.searchResultsDelegate respondsToSelector:@selector(searchController:willShowEmptyView:)]) {
[self.searchResultsDelegate searchController:self willShowEmptyView:self.emptyView];
}
Expand Down
42 changes: 28 additions & 14 deletions QMUIKit/UIKitExtensions/QMUITableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ - (void)didInitializedWithStyle:(UITableViewCellStyle)style {

// iOS7下背景色默认白色,之前的版本背景色继承tableView,这里统一设置为白色
self.backgroundColor = TableViewCellBackgroundColor;
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = TableViewCellSelectedBackgroundColor;
self.selectedBackgroundView = selectedBackgroundView;
UIColor *selectedBackgroundColor = TableViewCellSelectedBackgroundColor;
if (selectedBackgroundColor) {
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = selectedBackgroundColor;
self.selectedBackgroundView = selectedBackgroundView;
}

// 因为在hitTest里扩大了accessoryView的响应范围,因此提高了系统一个与此相关的bug的出现几率,所以又在scrollView.delegate里做一些补丁性质的东西来修复
if ([self.subviews.firstObject isKindOfClass:[UIScrollView class]]) {
Expand Down Expand Up @@ -184,19 +187,30 @@ - (void)initDefaultAccessoryImageViewIfNeeded {
// 重写accessoryType,如果是UITableViewCellAccessoryDisclosureIndicator类型的,则使用 QMUIConfigurationTemplate.m 配置表里的图片
- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType {
[super setAccessoryType:accessoryType];

if (accessoryType == UITableViewCellAccessoryDisclosureIndicator) {
[self initDefaultAccessoryImageViewIfNeeded];
self.defaultAccessoryImageView.image = TableViewCellDisclosureIndicatorImage;
[self.defaultAccessoryImageView sizeToFit];
self.accessoryView = self.defaultAccessoryImageView;
} else if (accessoryType == UITableViewCellAccessoryCheckmark) {
[self initDefaultAccessoryImageViewIfNeeded];
self.defaultAccessoryImageView.image = TableViewCellCheckmarkImage;
[self.defaultAccessoryImageView sizeToFit];
self.accessoryView = self.defaultAccessoryImageView;
} else {
self.accessoryView = nil;
UIImage *indicatorImage = TableViewCellDisclosureIndicatorImage;
if (indicatorImage) {
[self initDefaultAccessoryImageViewIfNeeded];
self.defaultAccessoryImageView.image = TableViewCellDisclosureIndicatorImage;
[self.defaultAccessoryImageView sizeToFit];
self.accessoryView = self.defaultAccessoryImageView;
return;
}
}

if (accessoryType == UITableViewCellAccessoryCheckmark) {
UIImage *checkmarkImage = TableViewCellCheckmarkImage;
if (checkmarkImage) {
[self initDefaultAccessoryImageViewIfNeeded];
self.defaultAccessoryImageView.image = TableViewCellCheckmarkImage;
[self.defaultAccessoryImageView sizeToFit];
self.accessoryView = self.defaultAccessoryImageView;
return;
}
}

self.accessoryView = nil;
}

#pragma mark - <UIScrollViewDelegate>
Expand Down
Loading

0 comments on commit 50c73b3

Please sign in to comment.