diff --git a/QMUIConfigurationTemplate/QMUIConfigurationTemplate.h b/QMUIConfigurationTemplate/QMUIConfigurationTemplate.h index 81da980d..b93dcf17 100644 --- a/QMUIConfigurationTemplate/QMUIConfigurationTemplate.h +++ b/QMUIConfigurationTemplate/QMUIConfigurationTemplate.h @@ -11,9 +11,7 @@ * QMUIConfigurationTemplate 是一份配置表,用于配合 QMUIKit 来管理整个 App 的全局样式,使用方式如下: * 1. 在 QMUI 项目代码的文件夹里找到 QMUIConfigurationTemplate 目录,把里面所有文件复制到自己项目里。 * 2. 在自己项目的 AppDelegate 里 #import "QMUIConfigurationTemplate.h",然后在 application:didFinishLaunchingWithOptions: 里调用 [QMUIConfigurationTemplate setupConfigurationTemplate],即可让配置表生效。 - * 3. 默认情况下配置表里的所有赋值都被注释,表示使用 QMUI 的默认值,你可以把你想修改的表达式取消注释,并改为想要的值即可。 - * 4. 注意如果修改了属性 A,则请搜索整个文件里所有用到 A 的地方,把那个地方的注释也打开,否则使用的是 A 在 QMUI 里的默认值,而不是你修改后的值。 - * 5. 更新 QMUIKit 的版本时,请留意 Release Log 里是否有提醒更新配置表,请尽量保持自己项目里的配置表与 QMUIKit 里的配置表一致,避免遗漏新的属性。 + * 3. 更新 QMUIKit 的版本时,请留意 Release Log 里是否有提醒更新配置表,请尽量保持自己项目里的配置表与 QMUIKit 里的配置表一致,避免遗漏新的属性。 */ @interface QMUIConfigurationTemplate : NSObject diff --git a/QMUIConfigurationTemplate/QMUIConfigurationTemplate.m b/QMUIConfigurationTemplate/QMUIConfigurationTemplate.m index ef2d539f..c2b66bc1 100644 --- a/QMUIConfigurationTemplate/QMUIConfigurationTemplate.m +++ b/QMUIConfigurationTemplate/QMUIConfigurationTemplate.m @@ -17,164 +17,162 @@ + (void)setupConfigurationTemplate { #pragma mark - Global Color - //- QMUICMI.clearColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0]; // UIColorClear : 透明色 - //- QMUICMI.whiteColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // UIColorWhite : 白色(不用 [UIColor whiteColor] 是希望保持颜色空间为 RGB) - //- QMUICMI.blackColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // UIColorBlack : 黑色(不用 [UIColor blackColor] 是希望保持颜色空间为 RGB) - //- QMUICMI.grayColor = UIColorMake(179, 179, 179); // UIColorGray : 最常用的灰色 - //- QMUICMI.grayDarkenColor = UIColorMake(163, 163, 163); // UIColorGrayDarken : 深一点的灰色 - //- QMUICMI.grayLightenColor = UIColorMake(198, 198, 198); // UIColorGrayLighten : 浅一点的灰色 - //- QMUICMI.redColor = UIColorMake(227, 40, 40); // UIColorRed : 红色 - //- QMUICMI.greenColor = UIColorMake(79, 214, 79); // UIColorGreen : 绿色 - //- QMUICMI.blueColor = UIColorMake(43, 133, 208); // UIColorBlue : 蓝色 - //- QMUICMI.yellowColor = UIColorMake(255, 252, 233); // UIColorYellow : 黄色 - - //- QMUICMI.linkColor = UIColorMake(56, 116, 171); // UIColorLink : 文字链接颜色 - //- QMUICMI.disabledColor = UIColorGray; // UIColorDisabled : 全局 disabled 的颜色,一般用于 UIControl 等控件 - //- QMUICMI.backgroundColor = UIColorMake(246, 246, 246); // UIColorForBackground : 界面背景色,默认用于 QMUICommonViewController.view 的背景色 - //- QMUICMI.maskDarkColor = UIColorMakeWithRGBA(0, 0, 0, .35f); // UIColorMask : 深色的背景遮罩,默认用于 QMAlertController、QMUIDialogViewController 等弹出控件的遮罩 - //- QMUICMI.maskLightColor = UIColorMakeWithRGBA(255, 255, 255, .5f); // UIColorMaskWhite : 浅色的背景遮罩,QMUIKit 里默认没用到,只是占个位 - //- QMUICMI.separatorColor = UIColorMake(200, 199, 204); // UIColorSeparator : 全局默认的分割线颜色,默认用于列表分隔线颜色、UIView (QMUI_Border) 分隔线颜色 - //- QMUICMI.separatorDashedColor = UIColorMake(17, 17, 17); // UIColorSeparatorDashed : 全局默认的虚线分隔线的颜色,默认 QMUIKit 暂时没用到 - //- QMUICMI.placeholderColor = UIColorMake(187, 187, 187); // UIColorPlaceholder,全局的输入框的 placeholder 颜色,默认用于 QMUITextField、QMUITextView,不影响系统 UIKit 的输入框 - - // UIColorTestRed/UIColorTestGreen/UIColorTestBlue = 测试用的颜色 - //- QMUICMI.testColorRed = UIColorMakeWithRGBA(255, 0, 0, .3); - //- QMUICMI.testColorGreen = UIColorMakeWithRGBA(0, 255, 0, .3); - //- QMUICMI.testColorBlue = UIColorMakeWithRGBA(0, 0, 255, .3); + QMUICMI.clearColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0]; // UIColorClear : 透明色 + QMUICMI.whiteColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // UIColorWhite : 白色(不用 [UIColor whiteColor] 是希望保持颜色空间为 RGB) + QMUICMI.blackColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // UIColorBlack : 黑色(不用 [UIColor blackColor] 是希望保持颜色空间为 RGB) + QMUICMI.grayColor = UIColorMake(179, 179, 179); // UIColorGray : 最常用的灰色 + QMUICMI.grayDarkenColor = UIColorMake(163, 163, 163); // UIColorGrayDarken : 深一点的灰色 + QMUICMI.grayLightenColor = UIColorMake(198, 198, 198); // UIColorGrayLighten : 浅一点的灰色 + QMUICMI.redColor = UIColorMake(250, 58, 58); // UIColorRed : 红色 + QMUICMI.greenColor = UIColorMake(159, 214, 97); // UIColorGreen : 绿色 + QMUICMI.blueColor = UIColorMake(49, 189, 243); // UIColorBlue : 蓝色 + QMUICMI.yellowColor = UIColorMake(255, 207, 71); // UIColorYellow : 黄色 + + QMUICMI.linkColor = UIColorMake(56, 116, 171); // UIColorLink : 文字链接颜色 + QMUICMI.disabledColor = UIColorGray; // UIColorDisabled : 全局 disabled 的颜色,一般用于 UIControl 等控件 + QMUICMI.backgroundColor = UIColorMake(246, 246, 246); // UIColorForBackground : 界面背景色,默认用于 QMUICommonViewController.view 的背景色 + QMUICMI.maskDarkColor = UIColorMakeWithRGBA(0, 0, 0, .35f); // UIColorMask : 深色的背景遮罩,默认用于 QMAlertController、QMUIDialogViewController 等弹出控件的遮罩 + QMUICMI.maskLightColor = UIColorMakeWithRGBA(255, 255, 255, .5f); // UIColorMaskWhite : 浅色的背景遮罩,QMUIKit 里默认没用到,只是占个位 + QMUICMI.separatorColor = UIColorMake(222, 224, 226); // UIColorSeparator : 全局默认的分割线颜色,默认用于列表分隔线颜色、UIView (QMUI_Border) 分隔线颜色 + QMUICMI.separatorDashedColor = UIColorMake(17, 17, 17); // UIColorSeparatorDashed : 全局默认的虚线分隔线的颜色,默认 QMUIKit 暂时没用到 + QMUICMI.placeholderColor = UIColorMake(196, 200, 208); // UIColorPlaceholder,全局的输入框的 placeholder 颜色,默认用于 QMUITextField、QMUITextView,不影响系统 UIKit 的输入框 + + // 测试用的颜色 + QMUICMI.testColorRed = UIColorMakeWithRGBA(255, 0, 0, .3); + QMUICMI.testColorGreen = UIColorMakeWithRGBA(0, 255, 0, .3); + QMUICMI.testColorBlue = UIColorMakeWithRGBA(0, 0, 255, .3); #pragma mark - UIControl - //- QMUICMI.controlHighlightedAlpha = 0.5f; // UIControlHighlightedAlpha : UIControl 系列控件在 highlighted 时的 alpha,默认用于 QMUIButton、 QMUINavigationTitleView - //- QMUICMI.controlDisabledAlpha = 0.5f; // UIControlDisabledAlpha : UIControl 系列控件在 disabled 时的 alpha,默认用于 QMUIButton + QMUICMI.controlHighlightedAlpha = 0.5f; // UIControlHighlightedAlpha : UIControl 系列控件在 highlighted 时的 alpha,默认用于 QMUIButton、 QMUINavigationTitleView + QMUICMI.controlDisabledAlpha = 0.5f; // UIControlDisabledAlpha : UIControl 系列控件在 disabled 时的 alpha,默认用于 QMUIButton #pragma mark - UIButton - //- QMUICMI.buttonHighlightedAlpha = UIControlHighlightedAlpha; // ButtonHighlightedAlpha : QMUIButton 在 highlighted 时的 alpha,不影响系统的 UIButton - //- QMUICMI.buttonDisabledAlpha = UIControlDisabledAlpha; // ButtonDisabledAlpha : QMUIButton 在 disabled 时的 alpha,不影响系统的 UIButton - //- QMUICMI.buttonTintColor = UIColorBlue; // ButtonTintColor : QMUIButton 默认的 tintColor,不影响系统的 UIButton + QMUICMI.buttonHighlightedAlpha = UIControlHighlightedAlpha; // ButtonHighlightedAlpha : QMUIButton 在 highlighted 时的 alpha,不影响系统的 UIButton + QMUICMI.buttonDisabledAlpha = UIControlDisabledAlpha; // ButtonDisabledAlpha : QMUIButton 在 disabled 时的 alpha,不影响系统的 UIButton + QMUICMI.buttonTintColor = UIColorBlue; // ButtonTintColor : QMUIButton 默认的 tintColor,不影响系统的 UIButton - //- QMUICMI.ghostButtonColorBlue = UIColorBlue; // GhostButtonColorBlue : QMUIGhostButtonColorBlue 的颜色 - //- QMUICMI.ghostButtonColorRed = UIColorRed; // GhostButtonColorRed : QMUIGhostButtonColorRed 的颜色 - //- QMUICMI.ghostButtonColorGreen = UIColorGreen; // GhostButtonColorGreen : QMUIGhostButtonColorGreen 的颜色 - //- QMUICMI.ghostButtonColorGray = UIColorGray; // GhostButtonColorGray : QMUIGhostButtonColorGray 的颜色 - //- QMUICMI.ghostButtonColorWhite = UIColorWhite; // GhostButtonColorWhite : QMUIGhostButtonColorWhite 的颜色 + QMUICMI.ghostButtonColorBlue = UIColorBlue; // GhostButtonColorBlue : QMUIGhostButtonColorBlue 的颜色 + QMUICMI.ghostButtonColorRed = UIColorRed; // GhostButtonColorRed : QMUIGhostButtonColorRed 的颜色 + QMUICMI.ghostButtonColorGreen = UIColorGreen; // GhostButtonColorGreen : QMUIGhostButtonColorGreen 的颜色 + QMUICMI.ghostButtonColorGray = UIColorGray; // GhostButtonColorGray : QMUIGhostButtonColorGray 的颜色 + QMUICMI.ghostButtonColorWhite = UIColorWhite; // GhostButtonColorWhite : QMUIGhostButtonColorWhite 的颜色 - //- QMUICMI.fillButtonColorBlue = UIColorBlue; // FillButtonColorBlue : QMUIFillButtonColorBlue 的颜色 - //- QMUICMI.fillButtonColorRed = UIColorRed; // FillButtonColorRed : QMUIFillButtonColorRed 的颜色 - //- QMUICMI.fillButtonColorGreen = UIColorGreen; // FillButtonColorGreen : QMUIFillButtonColorGreen 的颜色 - //- QMUICMI.fillButtonColorGray = UIColorGray; // FillButtonColorGray : QMUIFillButtonColorGray 的颜色 - //- QMUICMI.fillButtonColorWhite = UIColorWhite; // FillButtonColorWhite : QMUIFillButtonColorWhite 的颜色 + QMUICMI.fillButtonColorBlue = UIColorBlue; // FillButtonColorBlue : QMUIFillButtonColorBlue 的颜色 + QMUICMI.fillButtonColorRed = UIColorRed; // FillButtonColorRed : QMUIFillButtonColorRed 的颜色 + QMUICMI.fillButtonColorGreen = UIColorGreen; // FillButtonColorGreen : QMUIFillButtonColorGreen 的颜色 + QMUICMI.fillButtonColorGray = UIColorGray; // FillButtonColorGray : QMUIFillButtonColorGray 的颜色 + QMUICMI.fillButtonColorWhite = UIColorWhite; // FillButtonColorWhite : QMUIFillButtonColorWhite 的颜色 #pragma mark - TextField & TextView - //- QMUICMI.textFieldTintColor = UIColorBlue; // TextFieldTintColor : QMUITextField、QMUITextView 的 tintColor,不影响 UIKit 的输入框 - //- QMUICMI.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7); // TextFieldTextInsets : QMUITextField 的内边距,不影响 UITextField + QMUICMI.textFieldTintColor = nil; // TextFieldTintColor : QMUITextField、QMUITextView 的 tintColor,不影响 UIKit 的输入框 + QMUICMI.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7); // TextFieldTextInsets : QMUITextField 的内边距,不影响 UITextField #pragma mark - NavigationBar - //- QMUICMI.navBarHighlightedAlpha = 0.2f; // NavBarHighlightedAlpha : QMUINavigationButton 在 highlighted 时的 alpha - //- QMUICMI.navBarDisabledAlpha = 0.2f; // NavBarDisabledAlpha : QMUINavigationButton 在 disabled 时的 alpha - //- QMUICMI.navBarButtonFont = UIFontMake(17); // NavBarButtonFont : QMUINavigationButton 的字体 - //- QMUICMI.navBarButtonFontBold = UIFontBoldMake(17); // NavBarButtonFontBold : QMUINavigationButtonTypeBold 的字体 - //- QMUICMI.navBarBackgroundImage = nil; // NavBarBackgroundImage : UINavigationBar 的背景图 - //- QMUICMI.navBarShadowImage = nil; // NavBarShadowImage : UINavigationBar.shadowImage,也即导航栏底部那条分隔线 - //- QMUICMI.navBarBarTintColor = nil; // NavBarBarTintColor : UINavigationBar.barTintColor,也即背景色 - //- QMUICMI.navBarTintColor = UIColorBlack; // NavBarTintColor : UINavigationBar 的 tintColor,也即导航栏上面的按钮颜色 - //- QMUICMI.navBarTitleColor = NavBarTintColor; // NavBarTitleColor : UINavigationBar 的标题颜色,以及 QMUINavigationTitleView 的默认文字颜色 - //- QMUICMI.navBarTitleFont = UIFontBoldMake(17); // NavBarTitleFont : UINavigationBar 的标题字体,以及 QMUINavigationTitleView 的默认字体 - //- QMUICMI.navBarBackButtonTitlePositionAdjustment = UIOffsetZero; // NavBarBarBackButtonTitlePositionAdjustment : 导航栏返回按钮的文字偏移 - //- QMUICMI.navBarBackIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavBack size:CGSizeMake(12, 20) tintColor:NavBarTintColor]; // NavBarBackIndicatorImage : 导航栏的返回按钮的图片 - //- QMUICMI.navBarCloseButtonImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavClose size:CGSizeMake(16, 16) tintColor:NavBarTintColor]; // NavBarCloseButtonImage : QMUINavigationButton 用到的 × 的按钮图片 - - //- QMUICMI.navBarLoadingMarginRight = 3; // NavBarLoadingMarginRight : QMUINavigationTitleView 里左边 loading 的右边距 - //- QMUICMI.navBarAccessoryViewMarginLeft = 5; // NavBarAccessoryViewMarginLeft : QMUINavigationTitleView 里右边 accessoryView 的左边距 - //- QMUICMI.navBarActivityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; // NavBarActivityIndicatorViewStyle : QMUINavigationTitleView 里左边 loading 的主题 - //- QMUICMI.navBarAccessoryViewTypeDisclosureIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeTriangle size:CGSizeMake(8, 5) tintColor:UIColorWhite]; // NavBarAccessoryViewTypeDisclosureIndicatorImage : QMUINavigationTitleView 右边箭头的图片 + QMUICMI.navBarHighlightedAlpha = 0.2f; // NavBarHighlightedAlpha : QMUINavigationButton 在 highlighted 时的 alpha + QMUICMI.navBarDisabledAlpha = 0.2f; // NavBarDisabledAlpha : QMUINavigationButton 在 disabled 时的 alpha + QMUICMI.navBarButtonFont = nil; // NavBarButtonFont : QMUINavigationButton 的字体 + QMUICMI.navBarButtonFontBold = nil; // NavBarButtonFontBold : QMUINavigationButtonTypeBold 的字体 + QMUICMI.navBarBackgroundImage = nil; // NavBarBackgroundImage : UINavigationBar 的背景图 + QMUICMI.navBarShadowImage = nil; // NavBarShadowImage : UINavigationBar.shadowImage,也即导航栏底部那条分隔线 + QMUICMI.navBarBarTintColor = nil; // NavBarBarTintColor : UINavigationBar.barTintColor,也即背景色 + QMUICMI.navBarTintColor = nil; // NavBarTintColor : UINavigationBar 的 tintColor,也即导航栏上面的按钮颜色 + QMUICMI.navBarTitleColor = UIColorBlack; // NavBarTitleColor : UINavigationBar 的标题颜色,以及 QMUINavigationTitleView 的默认文字颜色 + QMUICMI.navBarTitleFont = nil; // NavBarTitleFont : UINavigationBar 的标题字体,以及 QMUINavigationTitleView 的默认字体 + QMUICMI.navBarBackButtonTitlePositionAdjustment = UIOffsetZero; // NavBarBarBackButtonTitlePositionAdjustment : 导航栏返回按钮的文字偏移 + QMUICMI.navBarBackIndicatorImage = nil; // NavBarBackIndicatorImage : 导航栏的返回按钮的图片 + QMUICMI.navBarCloseButtonImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavClose size:CGSizeMake(16, 16) tintColor:NavBarTintColor]; // NavBarCloseButtonImage : QMUINavigationButton 用到的 × 的按钮图片 + + QMUICMI.navBarLoadingMarginRight = 3; // NavBarLoadingMarginRight : QMUINavigationTitleView 里左边 loading 的右边距 + QMUICMI.navBarAccessoryViewMarginLeft = 5; // NavBarAccessoryViewMarginLeft : QMUINavigationTitleView 里右边 accessoryView 的左边距 + QMUICMI.navBarActivityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;// NavBarActivityIndicatorViewStyle : QMUINavigationTitleView 里左边 loading 的主题 + QMUICMI.navBarAccessoryViewTypeDisclosureIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeTriangle size:CGSizeMake(8, 5) tintColor:UIColorWhite]; // NavBarAccessoryViewTypeDisclosureIndicatorImage : QMUINavigationTitleView 右边箭头的图片 #pragma mark - TabBar - //- QMUICMI.tabBarBackgroundImage = nil; // TabBarBackgroundImage : UITabBar 的背景图 - //- QMUICMI.tabBarBarTintColor = nil; // TabBarBarTintColor : UITabBar 的 barTintColor - //- QMUICMI.tabBarShadowImageColor = nil; // TabBarShadowImageColor : UITabBar 的 shadowImage 的颜色,会自动创建一张 1px 高的图片 - //- QMUICMI.tabBarTintColor = UIColorMake(22, 147, 229); // TabBarTintColor : UITabBar 的 tintColor - //- QMUICMI.tabBarItemTitleColor = UIColorMake(119, 119, 119); // TabBarItemTitleColor : 未选中的 UITabBarItem 的标题颜色 - //- QMUICMI.tabBarItemTitleColorSelected = TabBarTintColor; // TabBarItemTitleColorSelected : 选中的 UITabBarItem 的标题颜色 + QMUICMI.tabBarBackgroundImage = nil; // TabBarBackgroundImage : UITabBar 的背景图 + QMUICMI.tabBarBarTintColor = nil; // TabBarBarTintColor : UITabBar 的 barTintColor + QMUICMI.tabBarShadowImageColor = nil; // TabBarShadowImageColor : UITabBar 的 shadowImage 的颜色,会自动创建一张 1px 高的图片 + QMUICMI.tabBarTintColor = nil; // TabBarTintColor : UITabBar 的 tintColor + QMUICMI.tabBarItemTitleColor = nil; // TabBarItemTitleColor : 未选中的 UITabBarItem 的标题颜色 + QMUICMI.tabBarItemTitleColorSelected = TabBarTintColor; // TabBarItemTitleColorSelected : 选中的 UITabBarItem 的标题颜色 #pragma mark - Toolbar - //- QMUICMI.toolBarHighlightedAlpha = 0.4f; // ToolBarHighlightedAlpha : QMUIToolbarButton 在 highlighted 状态下的 alpha - //- QMUICMI.toolBarDisabledAlpha = 0.4f; // ToolBarDisabledAlpha : QMUIToolbarButton 在 disabled 状态下的 alpha - //- QMUICMI.toolBarTintColor = UIColorBlue; // ToolBarTintColor : UIToolbar 的 tintColor,以及 QMUIToolbarButton normal 状态下的文字颜色 - //- QMUICMI.toolBarTintColorHighlighted = [ToolBarTintColor colorWithAlphaComponent:ToolBarHighlightedAlpha]; // ToolBarTintColorHighlighted : QMUIToolbarButton 在 highlighted 状态下的文字颜色 - //- QMUICMI.toolBarTintColorDisabled = [ToolBarTintColor colorWithAlphaComponent:ToolBarDisabledAlpha]; // ToolBarTintColorDisabled : QMUIToolbarButton 在 disabled 状态下的文字颜色 - //- QMUICMI.toolBarBackgroundImage = nil; // ToolBarBackgroundImage : UIToolbar 的背景图 - //- QMUICMI.toolBarBarTintColor = nil; // ToolBarBarTintColor : UIToolbar 的 tintColor - //- QMUICMI.toolBarShadowImageColor = UIColorMake(178, 178, 178); // ToolBarShadowImageColor : UIToolbar 的 shadowImage 的颜色,会自动创建一张 1px 高的图片 - //- QMUICMI.toolBarButtonFont = UIFontMake(17); // ToolBarButtonFont : QMUIToolbarButton 的字体 + QMUICMI.toolBarHighlightedAlpha = 0.4f; // ToolBarHighlightedAlpha : QMUIToolbarButton 在 highlighted 状态下的 alpha + QMUICMI.toolBarDisabledAlpha = 0.4f; // ToolBarDisabledAlpha : QMUIToolbarButton 在 disabled 状态下的 alpha + QMUICMI.toolBarTintColor = nil; // ToolBarTintColor : UIToolbar 的 tintColor,以及 QMUIToolbarButton normal 状态下的文字颜色 + QMUICMI.toolBarTintColorHighlighted = [ToolBarTintColor colorWithAlphaComponent:ToolBarHighlightedAlpha]; // ToolBarTintColorHighlighted : QMUIToolbarButton 在 highlighted 状态下的文字颜色 + QMUICMI.toolBarTintColorDisabled = [ToolBarTintColor colorWithAlphaComponent:ToolBarDisabledAlpha]; // ToolBarTintColorDisabled : QMUIToolbarButton 在 disabled 状态下的文字颜色 + QMUICMI.toolBarBackgroundImage = nil; // ToolBarBackgroundImage : UIToolbar 的背景图 + QMUICMI.toolBarBarTintColor = nil; // ToolBarBarTintColor : UIToolbar 的 tintColor + QMUICMI.toolBarShadowImageColor = nil; // ToolBarShadowImageColor : UIToolbar 的 shadowImage 的颜色,会自动创建一张 1px 高的图片 + QMUICMI.toolBarButtonFont = nil; // ToolBarButtonFont : QMUIToolbarButton 的字体 #pragma mark - SearchBar - //- QMUICMI.searchBarTextFieldBackground = UIColorWhite; // SearchBarTextFieldBackground : QMUISearchBar 里的文本框的背景颜色 - //- QMUICMI.searchBarTextFieldBorderColor = UIColorMake(205, 208, 210); // SearchBarTextFieldBorderColor : QMUISearchBar 里的文本框的边框颜色 - //- QMUICMI.searchBarBottomBorderColor = UIColorMake(205, 208, 210); // SearchBarBottomBorderColor : QMUISearchBar 底部分隔线颜色 - //- QMUICMI.searchBarBarTintColor = UIColorMake(247, 247, 247); // SearchBarBarTintColor : QMUISearchBar 的 barTintColor,也即背景色 - //- QMUICMI.searchBarTintColor = UIColorBlue; // SearchBarTintColor : QMUISearchBar 的 tintColor,也即上面的操作控件的主题色 - //- QMUICMI.searchBarTextColor = UIColorBlack; // SearchBarTextColor : QMUISearchBar 里的文本框的文字颜色 - //- QMUICMI.searchBarPlaceholderColor = UIColorPlaceholder; // SearchBarPlaceholderColor : QMUISearchBar 里的文本框的 placeholder 颜色 - //- QMUICMI.searchBarSearchIconImage = nil; // SearchBarSearchIconImage : QMUISearchBar 里的放大镜 icon - //- QMUICMI.searchBarClearIconImage = nil; // SearchBarClearIconImage : QMUISearchBar 里的文本框输入文字时右边的清空按钮的图片 - //- QMUICMI.searchBarTextFieldCornerRadius = 2.0; // SearchBarTextFieldCornerRadius : QMUISearchBar 里的文本框的圆角大小 + QMUICMI.searchBarTextFieldBackground = nil; // SearchBarTextFieldBackground : QMUISearchBar 里的文本框的背景颜色 + QMUICMI.searchBarTextFieldBorderColor = nil; // SearchBarTextFieldBorderColor : QMUISearchBar 里的文本框的边框颜色 + QMUICMI.searchBarBottomBorderColor = nil; // SearchBarBottomBorderColor : QMUISearchBar 底部分隔线颜色 + QMUICMI.searchBarBarTintColor = nil; // SearchBarBarTintColor : QMUISearchBar 的 barTintColor,也即背景色 + QMUICMI.searchBarTintColor = nil; // SearchBarTintColor : QMUISearchBar 的 tintColor,也即上面的操作控件的主题色 + QMUICMI.searchBarTextColor = nil; // SearchBarTextColor : QMUISearchBar 里的文本框的文字颜色 + QMUICMI.searchBarPlaceholderColor = UIColorPlaceholder; // SearchBarPlaceholderColor : QMUISearchBar 里的文本框的 placeholder 颜色 + QMUICMI.searchBarSearchIconImage = nil; // SearchBarSearchIconImage : QMUISearchBar 里的放大镜 icon + QMUICMI.searchBarClearIconImage = nil; // SearchBarClearIconImage : QMUISearchBar 里的文本框输入文字时右边的清空按钮的图片 + QMUICMI.searchBarTextFieldCornerRadius = 2.0; // SearchBarTextFieldCornerRadius : QMUISearchBar 里的文本框的圆角大小 #pragma mark - TableView / TableViewCell - //- QMUICMI.tableViewBackgroundColor = UIColorWhite; // TableViewBackgroundColor : Plain 类型的 QMUITableView 的背景色颜色 - //- QMUICMI.tableViewGroupedBackgroundColor = UIColorForBackground; // TableViewGroupedBackgroundColor : Grouped 类型的 QMUITableView 的背景色 - //- QMUICMI.tableSectionIndexColor = UIColorGrayDarken; // TableSectionIndexColor : 列表右边的字母索引条的文字颜色 - //- QMUICMI.tableSectionIndexBackgroundColor = UIColorClear; // TableSectionIndexBackgroundColor : 列表右边的字母索引条的背景色 - //- QMUICMI.tableSectionIndexTrackingBackgroundColor = UIColorClear; // TableSectionIndexTrackingBackgroundColor : 列表右边的字母索引条在选中时的背景色 - //- QMUICMI.tableViewSeparatorColor = UIColorSeparator; // TableViewSeparatorColor : 列表的分隔线颜色 - - //- QMUICMI.tableViewCellNormalHeight = 44; // TableViewCellNormalHeight : 列表默认的 cell 高度 - //- QMUICMI.tableViewCellTitleLabelColor = UIColorBlack; // TableViewCellTitleLabelColor : QMUITableViewCell 的 textLabel 的文字颜色 - //- QMUICMI.tableViewCellDetailLabelColor = UIColorGray; // TableViewCellDetailLabelColor : QMUITableViewCell 的 detailTextLabel 的文字颜色 - //- QMUICMI.tableViewCellContentDefaultPaddingLeft = 15; // TableViewCellContentDefaultPaddingLeft : QMUITableViewCell 的左边距 - //- QMUICMI.tableViewCellContentDefaultPaddingRight = 10; // TableViewCellContentDefaultPaddingRight : QMUITableViewCell 的右边距(最右截止到 accessoryView 的左边) - //- QMUICMI.tableViewCellBackgroundColor = UIColorWhite; // TableViewCellBackgroundColor : QMUITableViewCell 的背景色 - //- QMUICMI.tableViewCellSelectedBackgroundColor = UIColorMake(232, 232, 232); // TableViewCellSelectedBackgroundColor : QMUITableViewCell 点击时的背景色 - //- QMUICMI.tableViewCellWarningBackgroundColor = UIColorYellow; // TableViewCellWarningBackgroundColor : QMUITableViewCell 用于表示警告时的背景色,备用 - //- QMUICMI.tableViewCellDisclosureIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeDisclosureIndicator size:CGSizeMake(8, 13) tintColor:UIColorMakeWithRGBA(0, 0, 0, .2)]; // TableViewCellDisclosureIndicatorImage : QMUITableViewCell 当 accessoryType 为 UITableViewCellAccessoryDisclosureIndicator 时的箭头的图片 - //- QMUICMI.tableViewCellCheckmarkImage = [UIImage qmui_imageWithShape:QMUIImageShapeCheckmark size:CGSizeMake(15, 12) tintColor:UIColorBlue]; // TableViewCellCheckmarkImage : QMUITableViewCell 当 accessoryType 为 UITableViewCellAccessoryCheckmark 时的打钩的图片 - - //- QMUICMI.tableViewSectionHeaderBackgroundColor = UIColorMake(244, 244, 244); // TableViewSectionHeaderBackgroundColor : Plain 类型的 QMUITableView sectionHeader 的背景色 - //- QMUICMI.tableViewSectionFooterBackgroundColor = UIColorMake(244, 244, 244); // TableViewSectionFooterBackgroundColor : Plain 类型的 QMUITableView sectionFooter 的背景色 - //- QMUICMI.tableViewSectionHeaderFont = UIFontBoldMake(12); // TableViewSectionHeaderFont : Plain 类型的 QMUITableView sectionHeader 里的文字字体 - //- QMUICMI.tableViewSectionFooterFont = UIFontBoldMake(12); // TableViewSectionFooterFont : Plain 类型的 QMUITableView sectionFooter 里的文字字体 - //- QMUICMI.tableViewSectionHeaderTextColor = UIColorGrayDarken; // TableViewSectionHeaderTextColor : Plain 类型的 QMUITableView sectionHeader 里的文字颜色 - //- QMUICMI.tableViewSectionFooterTextColor = UIColorGray; // TableViewSectionFooterTextColor : Plain 类型的 QMUITableView sectionFooter 里的文字颜色 - //- QMUICMI.tableViewSectionHeaderHeight = 20; // TableViewSectionHeaderHeight : Plain 类型的 QMUITableView sectionHeader 的默认高度 - //- QMUICMI.tableViewSectionFooterHeight = 0; // TableViewSectionFooterHeight : Plain 类型的 QMUITableView sectionFooter 的默认高度 - //- QMUICMI.tableViewSectionHeaderContentInset = UIEdgeInsetsMake(4, 15, 4, 15); // TableViewSectionHeaderContentInset : Plain 类型的 QMUITableView sectionHeader 里的内容的 padding - //- QMUICMI.tableViewSectionFooterContentInset = UIEdgeInsetsMake(4, 15, 4, 15); // TableViewSectionFooterContentInset : Plain 类型的 QMUITableView sectionFooter 里的内容的 padding - - //- QMUICMI.tableViewGroupedSectionHeaderFont = UIFontMake(12); // TableViewGroupedSectionHeaderFont : Grouped 类型的 QMUITableView sectionHeader 里的文字字体 - //- QMUICMI.tableViewGroupedSectionFooterFont = UIFontMake(12); // TableViewGroupedSectionFooterFont : Grouped 类型的 QMUITableView sectionFooter 里的文字字体 - //- QMUICMI.tableViewGroupedSectionHeaderTextColor = UIColorGrayDarken; // TableViewGroupedSectionHeaderTextColor : Grouped 类型的 QMUITableView sectionHeader 里的文字颜色 - //- QMUICMI.tableViewGroupedSectionFooterTextColor = UIColorGray; // TableViewGroupedSectionFooterTextColor : Grouped 类型的 QMUITableView sectionFooter 里的文字颜色 - //- QMUICMI.tableViewGroupedSectionHeaderHeight = 15; // TableViewGroupedSectionHeaderHeight : Grouped 类型的 QMUITableView sectionHeader 的默认高度 - //- QMUICMI.tableViewGroupedSectionFooterHeight = 1; // TableViewGroupedSectionFooterHeight : Grouped 类型的 QMUITableView sectionFooter 的默认高度 - //- QMUICMI.tableViewGroupedSectionHeaderContentInset = UIEdgeInsetsMake(16, 15, 8, 15); // TableViewGroupedSectionHeaderContentInset : Grouped 类型的 QMUITableView sectionHeader 里的内容的 padding - //- QMUICMI.tableViewGroupedSectionFooterContentInset = UIEdgeInsetsMake(8, 15, 2, 15); // TableViewGroupedSectionFooterContentInset : Grouped 类型的 QMUITableView sectionFooter 里的内容的 padding + QMUICMI.tableViewBackgroundColor = UIColorWhite; // TableViewBackgroundColor : Plain 类型的 QMUITableView 的背景色颜色 + QMUICMI.tableViewGroupedBackgroundColor = UIColorForBackground; // TableViewGroupedBackgroundColor : Grouped 类型的 QMUITableView 的背景色 + QMUICMI.tableSectionIndexColor = nil; // TableSectionIndexColor : 列表右边的字母索引条的文字颜色 + QMUICMI.tableSectionIndexBackgroundColor = nil; // TableSectionIndexBackgroundColor : 列表右边的字母索引条的背景色 + QMUICMI.tableSectionIndexTrackingBackgroundColor = nil; // TableSectionIndexTrackingBackgroundColor : 列表右边的字母索引条在选中时的背景色 + QMUICMI.tableViewSeparatorColor = UIColorSeparator; // TableViewSeparatorColor : 列表的分隔线颜色 + + QMUICMI.tableViewCellNormalHeight = 44; // TableViewCellNormalHeight : 列表默认的 cell 高度 + QMUICMI.tableViewCellTitleLabelColor = nil; // TableViewCellTitleLabelColor : QMUITableViewCell 的 textLabel 的文字颜色 + QMUICMI.tableViewCellDetailLabelColor = nil; // TableViewCellDetailLabelColor : QMUITableViewCell 的 detailTextLabel 的文字颜色 + QMUICMI.tableViewCellBackgroundColor = UIColorWhite; // TableViewCellBackgroundColor : QMUITableViewCell 的背景色 + QMUICMI.tableViewCellSelectedBackgroundColor = UIColorMake(238, 239, 241); // TableViewCellSelectedBackgroundColor : QMUITableViewCell 点击时的背景色 + QMUICMI.tableViewCellWarningBackgroundColor = UIColorYellow; // TableViewCellWarningBackgroundColor : QMUITableViewCell 用于表示警告时的背景色,备用 + QMUICMI.tableViewCellDisclosureIndicatorImage = nil; // TableViewCellDisclosureIndicatorImage : QMUITableViewCell 当 accessoryType 为 UITableViewCellAccessoryDisclosureIndicator 时的箭头的图片 + QMUICMI.tableViewCellCheckmarkImage = nil; // TableViewCellCheckmarkImage : QMUITableViewCell 当 accessoryType 为 UITableViewCellAccessoryCheckmark 时的打钩的图片 + + QMUICMI.tableViewSectionHeaderBackgroundColor = UIColorMake(244, 244, 244); // TableViewSectionHeaderBackgroundColor : Plain 类型的 QMUITableView sectionHeader 的背景色 + QMUICMI.tableViewSectionFooterBackgroundColor = UIColorMake(244, 244, 244); // TableViewSectionFooterBackgroundColor : Plain 类型的 QMUITableView sectionFooter 的背景色 + QMUICMI.tableViewSectionHeaderFont = UIFontBoldMake(12); // TableViewSectionHeaderFont : Plain 类型的 QMUITableView sectionHeader 里的文字字体 + QMUICMI.tableViewSectionFooterFont = UIFontBoldMake(12); // TableViewSectionFooterFont : Plain 类型的 QMUITableView sectionFooter 里的文字字体 + QMUICMI.tableViewSectionHeaderTextColor = UIColorGrayDarken; // TableViewSectionHeaderTextColor : Plain 类型的 QMUITableView sectionHeader 里的文字颜色 + QMUICMI.tableViewSectionFooterTextColor = UIColorGray; // TableViewSectionFooterTextColor : Plain 类型的 QMUITableView sectionFooter 里的文字颜色 + QMUICMI.tableViewSectionHeaderHeight = 20; // TableViewSectionHeaderHeight : Plain 类型的 QMUITableView sectionHeader 的默认高度 + QMUICMI.tableViewSectionFooterHeight = 0; // TableViewSectionFooterHeight : Plain 类型的 QMUITableView sectionFooter 的默认高度 + QMUICMI.tableViewSectionHeaderContentInset = UIEdgeInsetsMake(4, 15, 4, 15); // TableViewSectionHeaderContentInset : Plain 类型的 QMUITableView sectionHeader 里的内容的 padding + QMUICMI.tableViewSectionFooterContentInset = UIEdgeInsetsMake(4, 15, 4, 15); // TableViewSectionFooterContentInset : Plain 类型的 QMUITableView sectionFooter 里的内容的 padding + + QMUICMI.tableViewGroupedSectionHeaderFont = UIFontMake(12); // TableViewGroupedSectionHeaderFont : Grouped 类型的 QMUITableView sectionHeader 里的文字字体 + QMUICMI.tableViewGroupedSectionFooterFont = UIFontMake(12); // TableViewGroupedSectionFooterFont : Grouped 类型的 QMUITableView sectionFooter 里的文字字体 + QMUICMI.tableViewGroupedSectionHeaderTextColor = UIColorGrayDarken; // TableViewGroupedSectionHeaderTextColor : Grouped 类型的 QMUITableView sectionHeader 里的文字颜色 + QMUICMI.tableViewGroupedSectionFooterTextColor = UIColorGray; // TableViewGroupedSectionFooterTextColor : Grouped 类型的 QMUITableView sectionFooter 里的文字颜色 + QMUICMI.tableViewGroupedSectionHeaderHeight = 15; // TableViewGroupedSectionHeaderHeight : Grouped 类型的 QMUITableView sectionHeader 的默认高度 + QMUICMI.tableViewGroupedSectionFooterHeight = 1; // TableViewGroupedSectionFooterHeight : Grouped 类型的 QMUITableView sectionFooter 的默认高度 + QMUICMI.tableViewGroupedSectionHeaderContentInset = UIEdgeInsetsMake(16, 15, 8, 15); // TableViewGroupedSectionHeaderContentInset : Grouped 类型的 QMUITableView sectionHeader 里的内容的 padding + QMUICMI.tableViewGroupedSectionFooterContentInset = UIEdgeInsetsMake(8, 15, 2, 15); // TableViewGroupedSectionFooterContentInset : Grouped 类型的 QMUITableView sectionFooter 里的内容的 padding #pragma mark - UIWindowLevel - //- QMUICMI.windowLevelQMUIAlertView = UIWindowLevelAlert - 4.0; // UIWindowLevelQMUIAlertView : QMUIModalPresentationViewController、QMUIPopupContainerView 里使用的 UIWindow 的 windowLevel - //- QMUICMI.windowLevelQMUIImagePreviewView = UIWindowLevelStatusBar + 1.0; // UIWindowLevelQMUIImagePreviewView : QMUIImagePreviewViewController 里使用的 UIWindow 的 windowLevel + QMUICMI.windowLevelQMUIAlertView = UIWindowLevelAlert - 4.0; // UIWindowLevelQMUIAlertView : QMUIModalPresentationViewController、QMUIPopupContainerView 里使用的 UIWindow 的 windowLevel + QMUICMI.windowLevelQMUIImagePreviewView = UIWindowLevelStatusBar + 1.0; // UIWindowLevelQMUIImagePreviewView : QMUIImagePreviewViewController 里使用的 UIWindow 的 windowLevel #pragma mark - Others - //- QMUICMI.supportedOrientationMask = UIInterfaceOrientationMaskPortrait; // SupportedOrientationMask : 默认支持的横竖屏方向 - //- QMUICMI.statusbarStyleLightInitially = NO; // StatusbarStyleLightInitially : 默认的状态栏内容是否使用白色,默认为 NO,也即黑色 - //- QMUICMI.needsBackBarButtonItemTitle = NO; // NeedsBackBarButtonItemTitle : 全局是否需要返回按钮的 title,不需要则只显示一个返回image - //- QMUICMI.hidesBottomBarWhenPushedInitially = YES; // HidesBottomBarWhenPushedInitially : QMUICommonViewController.hidesBottomBarWhenPushed 的初始值,默认为YES + QMUICMI.supportedOrientationMask = UIInterfaceOrientationMaskPortrait; // SupportedOrientationMask : 默认支持的横竖屏方向 + QMUICMI.statusbarStyleLightInitially = NO; // StatusbarStyleLightInitially : 默认的状态栏内容是否使用白色,默认为 NO,也即黑色 + QMUICMI.needsBackBarButtonItemTitle = NO; // NeedsBackBarButtonItemTitle : 全局是否需要返回按钮的 title,不需要则只显示一个返回image + QMUICMI.hidesBottomBarWhenPushedInitially = YES; // HidesBottomBarWhenPushedInitially : QMUICommonViewController.hidesBottomBarWhenPushed 的初始值,默认为YES } @end diff --git a/QMUIKit/UICommon/QMUIConfiguration.h b/QMUIKit/UICommon/QMUIConfiguration.h index ff586f48..9ef8394d 100644 --- a/QMUIKit/UICommon/QMUIConfiguration.h +++ b/QMUIKit/UICommon/QMUIConfiguration.h @@ -136,8 +136,6 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, assign) CGFloat tableViewCellNormalHeight; @property(nonatomic, strong, nullable) UIColor *tableViewCellTitleLabelColor; @property(nonatomic, strong, nullable) UIColor *tableViewCellDetailLabelColor; -@property(nonatomic, assign) CGFloat tableViewCellContentDefaultPaddingLeft; -@property(nonatomic, assign) CGFloat tableViewCellContentDefaultPaddingRight; @property(nonatomic, strong, nullable) UIColor *tableViewCellBackgroundColor; @property(nonatomic, strong, nullable) UIColor *tableViewCellSelectedBackgroundColor; @property(nonatomic, strong, nullable) UIColor *tableViewCellWarningBackgroundColor; diff --git a/QMUIKit/UICommon/QMUIConfiguration.m b/QMUIKit/UICommon/QMUIConfiguration.m index d8e1dcb3..252cc819 100644 --- a/QMUIKit/UICommon/QMUIConfiguration.m +++ b/QMUIKit/UICommon/QMUIConfiguration.m @@ -44,19 +44,19 @@ - (void)initDefaultConfiguration { self.grayColor = UIColorMake(179, 179, 179); self.grayDarkenColor = UIColorMake(163, 163, 163); self.grayLightenColor = UIColorMake(198, 198, 198); - self.redColor = UIColorMake(227, 40, 40); - self.greenColor = UIColorMake(79, 214, 79); - self.blueColor = UIColorMake(43, 133, 208); - self.yellowColor = UIColorMake(255, 252, 233); + self.redColor = UIColorMake(250, 58, 58); + self.greenColor = UIColorMake(159, 214, 97); + self.blueColor = UIColorMake(49, 189, 243); + self.yellowColor = UIColorMake(255, 207, 71); self.linkColor = UIColorMake(56, 116, 171); self.disabledColor = self.grayColor; self.backgroundColor = UIColorMake(246, 246, 246); self.maskDarkColor = UIColorMakeWithRGBA(0, 0, 0, .35f); self.maskLightColor = UIColorMakeWithRGBA(255, 255, 255, .5f); - self.separatorColor = UIColorMake(200, 199, 204); + self.separatorColor = UIColorMake(222, 224, 226); self.separatorDashedColor = UIColorMake(17, 17, 17); - self.placeholderColor = UIColorMake(187, 187, 187); + self.placeholderColor = UIColorMake(196, 200, 208); self.testColorRed = UIColorMakeWithRGBA(255, 0, 0, .3); self.testColorGreen = UIColorMakeWithRGBA(0, 255, 0, .3); @@ -87,59 +87,59 @@ - (void)initDefaultConfiguration { #pragma mark - UITextField & UITextView - self.textFieldTintColor = self.blueColor; + self.textFieldTintColor = nil; self.textFieldTextInsets = UIEdgeInsetsMake(0, 7, 0, 7); #pragma mark - NavigationBar self.navBarHighlightedAlpha = 0.2f; self.navBarDisabledAlpha = 0.2f; - self.navBarButtonFont = UIFontMake(17); - self.navBarButtonFontBold = UIFontBoldMake(17); + self.navBarButtonFont = nil; + self.navBarButtonFontBold = nil; self.navBarBackgroundImage = nil; self.navBarShadowImage = nil; self.navBarBarTintColor = nil; - self.navBarTintColor = self.blackColor; - self.navBarTitleColor = self.navBarTintColor; - self.navBarTitleFont = UIFontBoldMake(17); + self.navBarTintColor = nil; + self.navBarTitleColor = self.blackColor; + self.navBarTitleFont = nil; self.navBarBackButtonTitlePositionAdjustment = UIOffsetZero; - self.navBarBackIndicatorImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavBack size:CGSizeMake(12, 20) tintColor:self.navBarTintColor]; + self.navBarBackIndicatorImage = nil; self.navBarCloseButtonImage = [UIImage qmui_imageWithShape:QMUIImageShapeNavClose size:CGSizeMake(16, 16) tintColor:self.navBarTintColor]; self.navBarLoadingMarginRight = 3; self.navBarAccessoryViewMarginLeft = 5; self.navBarActivityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; - self.navBarAccessoryViewTypeDisclosureIndicatorImage = [[UIImage qmui_imageWithShape:QMUIImageShapeTriangle size:CGSizeMake(8, 5) tintColor:self.whiteColor] qmui_imageWithOrientation:UIImageOrientationDown]; + self.navBarAccessoryViewTypeDisclosureIndicatorImage = [[UIImage qmui_imageWithShape:QMUIImageShapeTriangle size:CGSizeMake(8, 5) tintColor:self.navBarTitleColor] qmui_imageWithOrientation:UIImageOrientationDown]; #pragma mark - TabBar self.tabBarBackgroundImage = nil; self.tabBarBarTintColor = nil; self.tabBarShadowImageColor = nil; - self.tabBarTintColor = UIColorMake(22, 147, 229); - self.tabBarItemTitleColor = UIColorMake(119, 119, 119); + self.tabBarTintColor = nil; + self.tabBarItemTitleColor = nil; self.tabBarItemTitleColorSelected = self.tabBarTintColor; #pragma mark - Toolbar self.toolBarHighlightedAlpha = 0.4f; self.toolBarDisabledAlpha = 0.4f; - self.toolBarTintColor = self.blueColor; + self.toolBarTintColor = nil; self.toolBarTintColorHighlighted = [self.toolBarTintColor colorWithAlphaComponent:self.toolBarHighlightedAlpha]; self.toolBarTintColorDisabled = [self.toolBarTintColor colorWithAlphaComponent:self.toolBarDisabledAlpha]; self.toolBarBackgroundImage = nil; self.toolBarBarTintColor = nil; - self.toolBarShadowImageColor = UIColorMake(178, 178, 178); - self.toolBarButtonFont = UIFontMake(17); + self.toolBarShadowImageColor = nil; + self.toolBarButtonFont = nil; #pragma mark - SearchBar - self.searchBarTextFieldBackground = self.whiteColor; - self.searchBarTextFieldBorderColor = UIColorMake(205, 208, 210); - self.searchBarBottomBorderColor = UIColorMake(205, 208, 210); - self.searchBarBarTintColor = UIColorMake(247, 247, 247); - self.searchBarTintColor = self.blueColor; - self.searchBarTextColor = self.blackColor; + self.searchBarTextFieldBackground = nil; + self.searchBarTextFieldBorderColor = nil; + self.searchBarBottomBorderColor = nil; + self.searchBarBarTintColor = nil; + self.searchBarTintColor = nil; + self.searchBarTextColor = nil; self.searchBarPlaceholderColor = self.placeholderColor; self.searchBarSearchIconImage = nil; self.searchBarClearIconImage = nil; @@ -149,21 +149,19 @@ - (void)initDefaultConfiguration { self.tableViewBackgroundColor = self.whiteColor; self.tableViewGroupedBackgroundColor = self.backgroundColor; - self.tableSectionIndexColor = self.grayDarkenColor; - self.tableSectionIndexBackgroundColor = self.clearColor; - self.tableSectionIndexTrackingBackgroundColor = self.clearColor; + self.tableSectionIndexColor = nil; + self.tableSectionIndexBackgroundColor = nil; + self.tableSectionIndexTrackingBackgroundColor = nil; self.tableViewSeparatorColor = self.separatorColor; self.tableViewCellNormalHeight = 44; - self.tableViewCellTitleLabelColor = self.blackColor; - self.tableViewCellDetailLabelColor = self.grayColor; - self.tableViewCellContentDefaultPaddingLeft = 15; - self.tableViewCellContentDefaultPaddingRight = 10; + self.tableViewCellTitleLabelColor = nil; + self.tableViewCellDetailLabelColor = nil; self.tableViewCellBackgroundColor = self.whiteColor; - self.tableViewCellSelectedBackgroundColor = UIColorMake(232, 232, 232); + self.tableViewCellSelectedBackgroundColor = UIColorMake(238, 239, 241); self.tableViewCellWarningBackgroundColor = self.yellowColor; - 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:self.blueColor]; + self.tableViewCellDisclosureIndicatorImage = nil; + self.tableViewCellCheckmarkImage = nil; self.tableViewSectionHeaderBackgroundColor = UIColorMake(244, 244, 244); self.tableViewSectionFooterBackgroundColor = UIColorMake(244, 244, 244); @@ -197,19 +195,27 @@ - (void)initDefaultConfiguration { self.hidesBottomBarWhenPushedInitially = YES; } +- (void)setNavBarTintColor:(UIColor *)navBarTintColor { + _navBarTintColor = navBarTintColor; + [QMUIHelper visibleViewController].navigationController.navigationBar.tintColor = _navBarTintColor; +} + - (void)setNavBarBarTintColor:(UIColor *)navBarBarTintColor { _navBarBarTintColor = navBarBarTintColor; [UINavigationBar appearance].barTintColor = _navBarBarTintColor; + [QMUIHelper visibleViewController].navigationController.navigationBar.barTintColor = _navBarBarTintColor; } - (void)setNavBarShadowImage:(UIImage *)navBarShadowImage { _navBarShadowImage = navBarShadowImage; [UINavigationBar appearance].shadowImage = _navBarShadowImage; + [QMUIHelper visibleViewController].navigationController.navigationBar.shadowImage = _navBarShadowImage; } - (void)setNavBarBackgroundImage:(UIImage *)navBarBackgroundImage { _navBarBackgroundImage = navBarBackgroundImage; [[UINavigationBar appearance] setBackgroundImage:_navBarBackgroundImage forBarMetrics:UIBarMetricsDefault]; + [[QMUIHelper visibleViewController].navigationController.navigationBar setBackgroundImage:_navBarBackgroundImage forBarMetrics:UIBarMetricsDefault]; } - (void)setNavBarTitleFont:(UIFont *)navBarTitleFont { @@ -223,6 +229,7 @@ - (void)setNavBarTitleFont:(UIFont *)navBarTitleFont { [titleTextAttributes setValue:self.navBarTitleColor forKey:NSForegroundColorAttributeName]; } [UINavigationBar appearance].titleTextAttributes = titleTextAttributes; + [QMUIHelper visibleViewController].navigationController.navigationBar.titleTextAttributes = titleTextAttributes; } } @@ -237,6 +244,7 @@ - (void)setNavBarTitleColor:(UIColor *)navBarTitleColor { [titleTextAttributes setValue:self.navBarTitleColor forKey:NSForegroundColorAttributeName]; } [UINavigationBar appearance].titleTextAttributes = titleTextAttributes; + [QMUIHelper visibleViewController].navigationController.navigationBar.titleTextAttributes = titleTextAttributes; } } @@ -245,6 +253,7 @@ - (void)setNavBarBackIndicatorImage:(UIImage *)navBarBackIndicatorImage { if (_navBarBackIndicatorImage) { UINavigationBar *navBarAppearance = [UINavigationBar appearance]; + UINavigationBar *navigationBar = [QMUIHelper visibleViewController].navigationController.navigationBar; // 返回按钮的图片frame是和系统默认的返回图片的大小一致的(13, 21),所以用自定义返回箭头时要保证图片大小与系统的箭头大小一样,否则无法对齐 CGSize systemBackIndicatorImageSize = CGSizeMake(13, 21); // 在iOS9上实际测量得到 @@ -259,6 +268,8 @@ - (void)setNavBarBackIndicatorImage:(UIImage *)navBarBackIndicatorImage { navBarAppearance.backIndicatorImage = _navBarBackIndicatorImage; navBarAppearance.backIndicatorTransitionMaskImage = navBarAppearance.backIndicatorImage; + navigationBar.backIndicatorImage = _navBarBackIndicatorImage; + navigationBar.backIndicatorTransitionMaskImage = navigationBar.backIndicatorImage; } } @@ -268,62 +279,81 @@ - (void)setNavBarBackButtonTitlePositionAdjustment:(UIOffset)navBarBackButtonTit if (!UIOffsetEqualToOffset(UIOffsetZero, _navBarBackButtonTitlePositionAdjustment)) { UIBarButtonItem *backBarButtonItem = [UIBarButtonItem appearance]; [backBarButtonItem setBackButtonTitlePositionAdjustment:_navBarBackButtonTitlePositionAdjustment forBarMetrics:UIBarMetricsDefault]; + [[QMUIHelper visibleViewController].navigationController.navigationItem.backBarButtonItem setBackButtonTitlePositionAdjustment:_navBarBackButtonTitlePositionAdjustment forBarMetrics:UIBarMetricsDefault]; } } +- (void)setToolBarTintColor:(UIColor *)toolBarTintColor { + _toolBarTintColor = toolBarTintColor; + [QMUIHelper visibleViewController].navigationController.toolbar.tintColor = _toolBarTintColor; +} + - (void)setToolBarBarTintColor:(UIColor *)toolBarBarTintColor { _toolBarBarTintColor = toolBarBarTintColor; [UIToolbar appearance].barTintColor = _toolBarBarTintColor; + [QMUIHelper visibleViewController].navigationController.toolbar.barTintColor = _toolBarBarTintColor; } - (void)setToolBarBackgroundImage:(UIImage *)toolBarBackgroundImage { _toolBarBackgroundImage = toolBarBackgroundImage; [[UIToolbar appearance] setBackgroundImage:_toolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; + [[QMUIHelper visibleViewController].navigationController.toolbar setBackgroundImage:_toolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; } - (void)setToolBarShadowImageColor:(UIColor *)toolBarShadowImageColor { _toolBarShadowImageColor = toolBarShadowImageColor; if (_toolBarShadowImageColor) { - [[UIToolbar appearance] setShadowImage:[UIImage qmui_imageWithColor:_toolBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0] forToolbarPosition:UIBarPositionAny]; + UIImage *shadowImage = [UIImage qmui_imageWithColor:_toolBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]; + [[UIToolbar appearance] setShadowImage:shadowImage forToolbarPosition:UIBarPositionAny]; + [[QMUIHelper visibleViewController].navigationController.toolbar setShadowImage:shadowImage forToolbarPosition:UIBarPositionAny]; } } -- (void)setToolBarButtonFont:(UIFont *)toolBarButtonFont { - _toolBarButtonFont = toolBarButtonFont; - if (_toolBarButtonFont) { - UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearance]; - [barButtonItemAppearance setTitleTextAttributes:@{NSFontAttributeName: _toolBarButtonFont} forState:UIControlStateNormal]; - } +- (void)setTabBarTintColor:(UIColor *)tabBarTintColor { + _tabBarTintColor = tabBarTintColor; + [QMUIHelper visibleViewController].tabBarController.tabBar.tintColor = _tabBarTintColor; } - (void)setTabBarBarTintColor:(UIColor *)tabBarBarTintColor { _tabBarBarTintColor = tabBarBarTintColor; [UITabBar appearance].barTintColor = _tabBarBarTintColor; + [QMUIHelper visibleViewController].tabBarController.tabBar.barTintColor = _tabBarBarTintColor; } - (void)setTabBarBackgroundImage:(UIImage *)tabBarBackgroundImage { _tabBarBackgroundImage = tabBarBackgroundImage; [UITabBar appearance].backgroundImage = _tabBarBackgroundImage; + [QMUIHelper visibleViewController].tabBarController.tabBar.backgroundImage = _tabBarBackgroundImage; } - (void)setTabBarShadowImageColor:(UIColor *)tabBarShadowImageColor { _tabBarShadowImageColor = tabBarShadowImageColor; if (_tabBarShadowImageColor) { - [[UITabBar appearance] setShadowImage:[UIImage qmui_imageWithColor:_tabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]]; + UIImage *shadowImage = [UIImage qmui_imageWithColor:_tabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]; + [[UITabBar appearance] setShadowImage:shadowImage]; + [QMUIHelper visibleViewController].tabBarController.tabBar.shadowImage = shadowImage; } } - (void)setTabBarItemTitleColor:(UIColor *)tabBarItemTitleColor { _tabBarItemTitleColor = tabBarItemTitleColor; if (_tabBarItemTitleColor) { - [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: _tabBarItemTitleColor} forState:UIControlStateNormal]; + NSDictionary *textAttributes = @{NSForegroundColorAttributeName: _tabBarItemTitleColor}; + [[UITabBarItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal]; + [[QMUIHelper visibleViewController].tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [obj setTitleTextAttributes:textAttributes forState:UIControlStateNormal]; + }]; } } - (void)setTabBarItemTitleColorSelected:(UIColor *)tabBarItemTitleColorSelected { _tabBarItemTitleColorSelected = tabBarItemTitleColorSelected; if (_tabBarItemTitleColorSelected) { - [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: _tabBarItemTitleColorSelected} forState:UIControlStateSelected]; + NSDictionary *textAttributes = @{NSForegroundColorAttributeName: _tabBarItemTitleColorSelected}; + [[UITabBarItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateSelected]; + [[QMUIHelper visibleViewController].tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [obj setTitleTextAttributes:textAttributes forState:UIControlStateSelected]; + }]; } } diff --git a/QMUIKit/UICommon/QMUIConfigurationMacros.h b/QMUIKit/UICommon/QMUIConfigurationMacros.h index 7033d0c2..a889dace 100644 --- a/QMUIKit/UICommon/QMUIConfigurationMacros.h +++ b/QMUIKit/UICommon/QMUIConfigurationMacros.h @@ -177,8 +177,6 @@ #define TableViewCellTitleLabelColor [QMUICMI tableViewCellTitleLabelColor] //cell的title颜色 #define TableViewCellDetailLabelColor [QMUICMI tableViewCellDetailLabelColor] //cell的detailTitle颜色 -#define TableViewCellContentDefaultPaddingLeft [QMUICMI tableViewCellContentDefaultPaddingLeft] // Cell默认左边缘的间距 -#define TableViewCellContentDefaultPaddingRight [QMUICMI tableViewCellContentDefaultPaddingRight] // Cell默认右边缘的间距 #pragma mark - UIWindowLevel #define UIWindowLevelQMUIAlertView [QMUICMI windowLevelQMUIAlertView] diff --git a/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h b/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h index a209efc6..aeb50233 100644 --- a/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h +++ b/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h @@ -8,20 +8,22 @@ #import -typedef enum { +/// Asset 的类型 +typedef NS_ENUM(NSUInteger, QMUIAssetType) { QMUIAssetTypeUnknow, // 未知类型的 Asset QMUIAssetTypeImage, // 图片类型的 Asset QMUIAssetTypeVideo, // 视频类型的 Asset QMUIAssetTypeAudio NS_ENUM_AVAILABLE_IOS(8_0), // 音频类型的 Asset,仅被 PhotoKit 支持,因此只适用于 iOS 8.0 QMUIAssetTypeLivePhoto NS_ENUM_AVAILABLE_IOS(9_1) // Live Photo 类型的 Asset,仅被 PhotoKit 支持,因此只适用于 iOS 9.1 -} QMUIAssetType; // Asset 的类型 +}; -typedef enum { +/// 从 iCloud 请求 Asset 大图的状态 +typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) { QMUIAssetDownloadStatusSucceed, // 下载成功或资源本来已经在本地 QMUIAssetDownloadStatusDownloading, // 下载中 QMUIAssetDownloadStatusCanceled, // 取消下载 QMUIAssetDownloadStatusFailed, // 下载失败 -} QMUIAssetDownloadStatus; // 从 iCloud 请求 Asset 大图的状态 +}; @class ALAsset; diff --git a/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsGroup.h b/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsGroup.h index 550e3804..cde88f02 100644 --- a/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsGroup.h +++ b/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsGroup.h @@ -15,17 +15,19 @@ @class QMUIAsset; -typedef enum { +/// 相册展示内容的类型 +typedef NS_ENUM(NSUInteger, QMUIAlbumContentType) { QMUIAlbumContentTypeAll, // 展示所有资源(照片和视频) QMUIAlbumContentTypeOnlyPhoto, // 只展示照片 QMUIAlbumContentTypeOnlyVideo, // 只展示视频 QMUIAlbumContentTypeOnlyAudio NS_ENUM_AVAILABLE_IOS(8_0) // 只展示音频 -} QMUIAlbumContentType; // 相册展示内容的类型 +}; -typedef enum { +/// 相册展示内容按日期排序的方式 +typedef NS_ENUM(NSUInteger, QMUIAlbumSortType) { QMUIAlbumSortTypePositive, // 日期最新的内容排在后面 QMUIAlbumSortTypeReverse // 日期最新的内容排在前面 -} QMUIAlbumSortType; // 相册展示内容按日期排序的方式 +}; @interface QMUIAssetsGroup : NSObject diff --git a/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsManager.h b/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsManager.h index 094c4fae..93ff4d3c 100644 --- a/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsManager.h +++ b/QMUIKit/UIComponents/AssetLibrary/QMUIAssetsManager.h @@ -21,12 +21,12 @@ #define EnforceUseAssetsLibraryForTest NO // 强制在 iOS 8.0 下也使用 ALAssetLibrary,用于调试 /// Asset授权的状态 -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIAssetAuthorizationStatus) { QMUIAssetAuthorizationStatusNotUsingPhotoKit, // 对于iOS7及以下不支持PhotoKit的系统,没有所谓的“授权状态”,所以定义一个特定的status用于表示这种情况 QMUIAssetAuthorizationStatusNotDetermined, // 还不确定有没有授权 QMUIAssetAuthorizationStatusAuthorized, // 已经授权 QMUIAssetAuthorizationStatusNotAuthorized // 手动禁止了授权 -} QMUIAssetAuthorizationStatus; +}; typedef void (^QMUIWriteAssetCompletionBlock)(QMUIAsset *asset, NSError *error); diff --git a/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.h b/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.h index 89f66ea4..c5503a6e 100644 --- a/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.h +++ b/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.h @@ -39,7 +39,7 @@ - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController didFinishPickingImageWithImagesAssetArray:(NSMutableArray *)imagesAssetArray; /** - * image被点击时调用(先调用这个接口,然后才去走预览大图的逻辑) + * cell 被点击时调用(先调用这个接口,然后才去走预览大图的逻辑),注意这并非指选中 checkbox 事件 * * @param imagePickerViewController 对应的 QMUIImagePickerViewController * @param imageAsset 被选中的图片的 QMUIAsset 对象 @@ -47,10 +47,16 @@ */ - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController didSelectImageWithImagesAsset:(QMUIAsset *)imageAsset afterImagePickerPreviewViewControllerUpdate:(QMUIImagePickerPreviewViewController *)imagePickerPreviewViewController; +/// 即将选中 checkbox 时调用 - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController willCheckImageAtIndex:(NSInteger)index; + +/// 选中了 checkbox 之后调用 - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController didCheckImageAtIndex:(NSInteger)index; +/// 即将取消选中 checkbox 时调用 - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController willUncheckImageAtIndex:(NSInteger)index; + +/// 取消了 checkbox 选中之后调用 - (void)imagePickerViewController:(QMUIImagePickerViewController *)imagePickerViewController didUncheckImageAtIndex:(NSInteger)index; /** diff --git a/QMUIKit/UIComponents/QMUIModalPresentationViewController.h b/QMUIKit/UIComponents/QMUIModalPresentationViewController.h index 1d332151..eb2471d6 100644 --- a/QMUIKit/UIComponents/QMUIModalPresentationViewController.h +++ b/QMUIKit/UIComponents/QMUIModalPresentationViewController.h @@ -11,11 +11,11 @@ @class QMUIModalPresentationViewController; @class QMUIModalPresentationWindow; -typedef enum : NSUInteger { +typedef NS_ENUM(NSUInteger, QMUIModalPresentationAnimationStyle) { QMUIModalPresentationAnimationStyleFade, // 渐现渐隐,默认 QMUIModalPresentationAnimationStylePopup, // 从中心点弹出 QMUIModalPresentationAnimationStyleSlide // 从下往上升起 -} QMUIModalPresentationAnimationStyle; +}; @protocol QMUIModalPresentationContentViewControllerProtocol diff --git a/QMUIKit/UIComponents/QMUINavigationTitleView.m b/QMUIKit/UIComponents/QMUINavigationTitleView.m index 33b2b03b..b805fc65 100644 --- a/QMUIKit/UIComponents/QMUINavigationTitleView.m +++ b/QMUIKit/UIComponents/QMUINavigationTitleView.m @@ -520,9 +520,11 @@ - (void)setStyle:(QMUINavigationTitleViewStyle)style { - (void)tintColorDidChange { [super tintColorDidChange]; - self.titleLabel.textColor = self.tintColor; - self.subtitleLabel.textColor = self.tintColor; - self.loadingView.color = self.tintColor; + + UIColor *color = self.tintColor; + self.titleLabel.textColor = color; + self.subtitleLabel.textColor = color; + self.loadingView.color = color; } #pragma mark - Events diff --git a/QMUIKit/UIComponents/QMUIPieProgressView.m b/QMUIKit/UIComponents/QMUIPieProgressView.m index 1e70990c..530dbc4b 100644 --- a/QMUIKit/UIComponents/QMUIPieProgressView.m +++ b/QMUIKit/UIComponents/QMUIPieProgressView.m @@ -78,6 +78,9 @@ + (Class)layerClass { - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { + self.backgroundColor = UIColorClear; + self.tintColor = UIColorBlue; + [self didInitialized]; } return self; @@ -86,6 +89,8 @@ - (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self didInitialized]; + // 从 xib 初始化的话,在 IB 里设置了 tintColor 也不会触发 tintColorDidChange,所以这里手动调用一下 + [self tintColorDidChange]; } return self; } @@ -94,12 +99,8 @@ - (void)didInitialized { self.progress = 0.0; self.progressAnimationDuration = 0.5; - self.backgroundColor = UIColorClear; - self.tintColor = UIColorBlue; self.layer.contentsScale = ScreenScale;// 要显示指定一个倍数 - self.layer.backgroundColor = UIColorClear.CGColor; self.layer.borderWidth = 1.0; - [self.layer setNeedsDisplay]; } diff --git a/QMUIKit/UIComponents/QMUIPopupContainerView.h b/QMUIKit/UIComponents/QMUIPopupContainerView.h index 3daecab8..71bb21a9 100644 --- a/QMUIKit/UIComponents/QMUIPopupContainerView.h +++ b/QMUIKit/UIComponents/QMUIPopupContainerView.h @@ -9,10 +9,10 @@ #import #import "UIControl+QMUI.h" -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIPopupContainerViewLayoutDirection) { QMUIPopupContainerViewLayoutDirectionAbove, QMUIPopupContainerViewLayoutDirectionBelow -} QMUIPopupContainerViewLayoutDirection; +}; /** * 带箭头的小tips浮层,自带 imageView 和 textLabel,可展示简单的图文信息。 diff --git a/QMUIKit/UIKitExtensions/QMUIButton.h b/QMUIKit/UIKitExtensions/QMUIButton.h index 3b917b05..94ec0180 100644 --- a/QMUIKit/UIKitExtensions/QMUIButton.h +++ b/QMUIKit/UIKitExtensions/QMUIButton.h @@ -9,41 +9,41 @@ #import /// 控制图片在UIButton里的位置,默认为QMUIButtonImagePositionLeft -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIButtonImagePosition) { QMUIButtonImagePositionTop, // imageView在titleLabel上面 QMUIButtonImagePositionLeft, // imageView在titleLabel左边 QMUIButtonImagePositionBottom, // imageView在titleLabel下面 QMUIButtonImagePositionRight, // imageView在titleLabel右边 -} QMUIButtonImagePosition; +}; -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIGhostButtonColor) { QMUIGhostButtonColorBlue, QMUIGhostButtonColorRed, QMUIGhostButtonColorGreen, QMUIGhostButtonColorGray, QMUIGhostButtonColorWhite, -} QMUIGhostButtonColor; +}; -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIFillButtonColor) { QMUIFillButtonColorBlue, QMUIFillButtonColorRed, QMUIFillButtonColorGreen, QMUIFillButtonColorGray, QMUIFillButtonColorWhite, -} QMUIFillButtonColor; +}; -typedef enum { +typedef NS_ENUM(NSUInteger, QMUINavigationButtonType) { QMUINavigationButtonTypeNormal, // 普通导航栏文字按钮 QMUINavigationButtonTypeBold, // 导航栏加粗按钮 QMUINavigationButtonTypeImage, // 图标按钮 QMUINavigationButtonTypeBack // 自定义返回按钮(可以同时带有title) -} QMUINavigationButtonType; +}; -typedef enum { +typedef NS_ENUM(NSUInteger, QMUIToolbarButtonType) { QMUIToolbarButtonTypeNormal, // 普通工具栏按钮 QMUIToolbarButtonTypeRed, // 工具栏红色按钮,用于删除等警告性操作 QMUIToolbarButtonTypeImage, // 图标类型的按钮 -} QMUIToolbarButtonType; +}; typedef NS_ENUM(NSInteger, QMUINavigationButtonPosition) { QMUINavigationButtonPositionNone = -1, // 不处于navigationBar最左(右)边的按钮,则使用None。用None则不会在alignmentRectInsets里调整位置 diff --git a/QMUIKit/UIKitExtensions/QMUIButton.m b/QMUIKit/UIKitExtensions/QMUIButton.m index a8428f18..0fe84281 100644 --- a/QMUIKit/UIKitExtensions/QMUIButton.m +++ b/QMUIKit/UIKitExtensions/QMUIButton.m @@ -34,6 +34,11 @@ @implementation QMUIButton - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self didInitialized]; + + self.tintColor = ButtonTintColor; + if (!self.adjustsTitleTintColorAutomatically) { + [self setTitleColor:self.tintColor forState:UIControlStateNormal]; + } } return self; } @@ -48,10 +53,6 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { - (void)didInitialized { self.adjustsTitleTintColorAutomatically = NO; self.adjustsImageTintColorAutomatically = NO; - self.tintColor = ButtonTintColor; - if (!self.adjustsTitleTintColorAutomatically) { - [self setTitleColor:self.tintColor forState:UIControlStateNormal]; - } // 默认接管highlighted和disabled的表现,去掉系统默认的表现 self.adjustsImageWhenHighlighted = NO; @@ -900,7 +901,6 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { - (void)didInitialized { [super didInitialized]; - [self setTitleColor:ButtonTintColor forState:UIControlStateNormal]; self.underlineLayer = [CALayer layer]; [self.underlineLayer qmui_removeDefaultAnimations]; diff --git a/QMUIKit/UIKitExtensions/QMUITableViewCell.m b/QMUIKit/UIKitExtensions/QMUITableViewCell.m index 8c4ee06d..4cb7855b 100644 --- a/QMUIKit/UIKitExtensions/QMUITableViewCell.m +++ b/QMUIKit/UIKitExtensions/QMUITableViewCell.m @@ -53,15 +53,19 @@ - (void)didInitializedWithStyle:(UITableViewCellStyle)style { _accessoryHitTestEdgeInsets = UIEdgeInsetsMake(-12, -12, -12, -12); self.textLabel.font = UIFontMake(16); - self.textLabel.textColor = TableViewCellTitleLabelColor; self.textLabel.backgroundColor = UIColorClear; + UIColor *titleLabelColor = TableViewCellTitleLabelColor; + if (titleLabelColor) { + self.textLabel.textColor = titleLabelColor; + } self.detailTextLabel.font = UIFontMake(15); - self.detailTextLabel.textColor = TableViewCellDetailLabelColor; self.detailTextLabel.backgroundColor = UIColorClear; + UIColor *detailLabelColor = TableViewCellDetailLabelColor; + if (detailLabelColor) { + self.detailTextLabel.textColor = detailLabelColor; + } - // iOS7下背景色默认白色,之前的版本背景色继承tableView,这里统一设置为白色 - self.backgroundColor = TableViewCellBackgroundColor; UIColor *selectedBackgroundColor = TableViewCellSelectedBackgroundColor; if (selectedBackgroundColor) { UIView *selectedBackgroundView = [[UIView alloc] init]; @@ -166,12 +170,21 @@ - (void)setEnabled:(BOOL)enabled { if (_enabled != enabled) { if (enabled) { self.userInteractionEnabled = YES; - self.textLabel.textColor = TableViewCellTitleLabelColor; - self.detailTextLabel.textColor = TableViewCellDetailLabelColor; + UIColor *titleLabelColor = TableViewCellTitleLabelColor; + if (titleLabelColor) { + self.textLabel.textColor = titleLabelColor; + } + UIColor *detailLabelColor = TableViewCellDetailLabelColor; + if (detailLabelColor) { + self.detailTextLabel.textColor = detailLabelColor; + } } else { self.userInteractionEnabled = NO; - self.textLabel.textColor = UIColorDisabled; - self.detailTextLabel.textColor = UIColorDisabled; + UIColor *disabledColor = UIColorDisabled; + if (disabledColor) { + self.textLabel.textColor = disabledColor; + self.detailTextLabel.textColor = disabledColor; + } } _enabled = enabled; } diff --git a/QMUIKit/UIKitExtensions/QMUITextField.m b/QMUIKit/UIKitExtensions/QMUITextField.m index 72fac3bc..4fbd408c 100644 --- a/QMUIKit/UIKitExtensions/QMUITextField.m +++ b/QMUIKit/UIKitExtensions/QMUITextField.m @@ -26,6 +26,7 @@ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self didInitialized]; + self.tintColor = TextFieldTintColor; } return self; } @@ -39,7 +40,6 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { - (void)didInitialized { self.delegate = self; - self.tintColor = TextFieldTintColor; self.placeholderColor = UIColorPlaceholder; self.textInsets = TextFieldTextInsets; self.shouldResponseToProgrammaticallyTextChanges = YES; diff --git a/QMUIKit/UIKitExtensions/QMUITextView.m b/QMUIKit/UIKitExtensions/QMUITextView.m index a30069ce..65c8e055 100644 --- a/QMUIKit/UIKitExtensions/QMUITextView.m +++ b/QMUIKit/UIKitExtensions/QMUITextView.m @@ -23,7 +23,6 @@ @interface QMUITextView () @property(nonatomic, assign) BOOL debug; @property(nonatomic, assign) BOOL shouldRejectSystemScroll;// 如果在 handleTextChanged: 里主动调整 contentOffset,则为了避免被系统的自动调整覆盖,会利用这个标记去屏蔽系统对 setContentOffset: 的调用 -@property(nonatomic, assign) BOOL callingSizeThatFitsByAutoResizable; // 标志本次调用 sizeThatFits: 是因为 handleTextChange: 里计算高度导致的 @property(nonatomic, strong) UILabel *placeholderLabel; @@ -39,6 +38,7 @@ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self didInitialized]; + self.tintColor = TextFieldTintColor; } return self; } @@ -54,7 +54,6 @@ - (void)didInitialized { self.debug = NO; self.delegate = self; self.scrollsToTop = NO; - self.tintColor = TextFieldTintColor; self.placeholderColor = UIColorPlaceholder; self.placeholderMargins = UIEdgeInsetsZero; self.autoResizable = NO; @@ -81,9 +80,17 @@ - (NSString *)description { return [NSString stringWithFormat:@"%@; text.length: %@ | %@; markedTextRange: %@", [super description], @(self.text.length), @([self lengthWithString:self.text]), self.markedTextRange]; } +- (BOOL)isCurrentTextDifferentOfText:(NSString *)text { + NSString *textBeforeChange = self.text;// UITextView 如果文字为空,self.text 永远返回 @"" 而不是 nil(即便你设置为 nil 后立即 get 出来也是) + if ([textBeforeChange isEqualToString:text] || (textBeforeChange.length == 0 && !text)) { + return NO; + } + return YES; +} + - (void)setText:(NSString *)text { NSString *textBeforeChange = self.text; - BOOL textDifferent = ![textBeforeChange isEqualToString:text]; + BOOL textDifferent = [self isCurrentTextDifferentOfText:text]; // 如果前后文字没变化,则什么都不做 if (!textDifferent) { @@ -121,7 +128,7 @@ - (void)setText:(NSString *)text { - (void)setAttributedText:(NSAttributedString *)attributedText { NSString *textBeforeChange = self.attributedText.string; - BOOL textDifferent = ![textBeforeChange isEqualToString:attributedText.string]; + BOOL textDifferent = [self isCurrentTextDifferentOfText:attributedText.string]; // 如果前后文字没变化,则什么都不做 if (!textDifferent) { @@ -217,10 +224,7 @@ - (void)handleTextChanged:(id)sender { // 计算高度 if (self.autoResizable) { - // 注意,这里 iOS 10 以下有兼容问题,请查看文件里的 sizeThatFits: - self.callingSizeThatFitsByAutoResizable = YES; CGFloat resultHeight = [textView sizeThatFits:CGSizeMake(CGRectGetWidth(self.bounds), CGFLOAT_MAX)].height; - self.callingSizeThatFitsByAutoResizable = NO; if (self.debug) NSLog(@"handleTextDidChange, text = %@, resultHeight = %f", textView.text, resultHeight); @@ -231,35 +235,17 @@ - (void)handleTextChanged:(id)sender { } } - // 系统的 UITextView 在文字可滚动的情况下在最后一行输入,文字是贴边的(并不会考虑 textContainerInset.bottom),所以这里接管了 UITextView 的文字滚动 - CGRect caretRect = [textView caretRectForPosition:textView.selectedTextRange.end]; - if (self.debug) NSLog(@"调整前,caretRect.maxY = %.2f, contentOffset.y = %.2f, contentSize.height = %.2f bounds.height = %.2f", CGRectGetMaxY(caretRect), textView.contentOffset.y, textView.contentSize.height, CGRectGetHeight(textView.bounds)); - - CGFloat caretMarginBottom = self.textContainerInset.bottom; - if (CGRectGetMaxY(caretRect) + caretMarginBottom >= textView.contentOffset.y + CGRectGetHeight(textView.bounds)) { - CGFloat contentOffsetY = fmax(0, ceil(CGRectGetMaxY(caretRect) + caretMarginBottom - CGRectGetHeight(textView.bounds))); - if (self.debug) NSLog(@"调整后,contentOffset.y = %.2f, contentSize.height = %.2f", contentOffsetY, textView.contentSize.height); - - self.shouldRejectSystemScroll = YES; - // 用 dispatch 延迟一下,因为在文字发生换行时,系统自己会做一些滚动,我们要延迟一点才能避免被系统的滚动覆盖 - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - self.shouldRejectSystemScroll = NO; - [textView setContentOffset:CGPointMake(textView.contentOffset.x, contentOffsetY) animated:NO]; - }); + // textView 尚未被展示到界面上时,此时过早进行光标调整会计算错误 + if (!textView.window) { + return; } - } -} - -- (CGSize)sizeThatFits:(CGSize)size { - // iOS 10 以下调用 sizeThatFits: 会导致文字跳动,因此自己计算 https://github.com/QMUI/QMUI_iOS/issues/92 - if (IOS_VERSION < 10.0 && self.callingSizeThatFitsByAutoResizable) { - CGFloat contentWidth = size.width - UIEdgeInsetsGetHorizontalValue(self.textContainerInset) - UIEdgeInsetsGetHorizontalValue(self.contentInset); - CGRect textRect = [self.attributedText boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; - CGSize resultSize = CGSizeMake(size.width, CGRectGetHeight(textRect) + UIEdgeInsetsGetVerticalValue(self.textContainerInset) + UIEdgeInsetsGetVerticalValue(self.contentInset)); - resultSize.height = fmin(size.height, resultSize.height); - return resultSize; - } else { - return [super sizeThatFits:size]; + + self.shouldRejectSystemScroll = YES; + // 用 dispatch 延迟一下,因为在文字发生换行时,系统自己会做一些滚动,我们要延迟一点才能避免被系统的滚动覆盖 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + self.shouldRejectSystemScroll = NO; + [self qmui_scrollCaretVisibleAnimated:NO]; + }); } } diff --git a/QMUIKit/UIKitExtensions/UIColor+QMUI.h b/QMUIKit/UIKitExtensions/UIColor+QMUI.h index 3ec91ed9..98e9ec16 100644 --- a/QMUIKit/UIKitExtensions/UIColor+QMUI.h +++ b/QMUIKit/UIKitExtensions/UIColor+QMUI.h @@ -95,6 +95,33 @@ */ - (UIColor *)qmui_transitionToColor:(UIColor *)toColor progress:(CGFloat)progress; +/** + * 判断当前颜色是否为深色,可用于根据不同色调动态设置不同文字颜色的场景。 + * + * @link http://stackoverflow.com/questions/19456288/text-color-based-on-background-image @/link + * + * @return 若为深色则返回“YES”,浅色则返回“NO” + */ +- (BOOL)qmui_colorIsDark; + +/** + * 当前颜色的反色 + * + * @link http://stackoverflow.com/questions/5893261/how-to-get-inverse-color-from-uicolor @/link + */ +- (UIColor *)qmui_inverseColor; + +/** + * 判断当前颜色是否等于系统默认的 tintColor 颜色。 + * 背景:如果将一个 UIView.tintColor 设置为 nil,表示这个 view 的 tintColor 希望跟随 superview.tintColor 变化而变化,所以设置完再获取 view.tintColor,得到的并非 nil,而是 superview.tintColor 的值,而如果整棵 view 层级树里的 view 都没有设置自己的 tintColor,则会返回系统默认的 tintColor(也即 [UIColor qmui_systemTintColor]),所以才提供这个方法用于代替判断 tintColor == nil 的作用。 + */ +- (BOOL)qmui_isSystemTintColor; + +/** + * 获取当前系统的默认 tintColor 色值 + */ ++ (UIColor *)qmui_systemTintColor; + /** * 计算两个颜色叠加之后的最终色(注意区分前景色后景色的顺序)
* @link http://stackoverflow.com/questions/10781953/determine-rgba-colour-received-by-combining-two-colours @/link @@ -114,20 +141,4 @@ */ + (UIColor *)qmui_randomColor; -/** - * 判断当前颜色是否为深色,可用于根据不同色调动态设置不同文字颜色的场景。 - * - * @link http://stackoverflow.com/questions/19456288/text-color-based-on-background-image @/link - * - * @return 若为深色则返回“YES”,浅色则返回“NO” - */ -- (BOOL)qmui_colorIsDark; - -/** - * 当前颜色的反色 - * - * @link http://stackoverflow.com/questions/5893261/how-to-get-inverse-color-from-uicolor @/link - */ -- (UIColor *)qmui_inverseColor; - @end diff --git a/QMUIKit/UIKitExtensions/UIColor+QMUI.m b/QMUIKit/UIKitExtensions/UIColor+QMUI.m index a8f00fba..c8b95cda 100644 --- a/QMUIKit/UIKitExtensions/UIColor+QMUI.m +++ b/QMUIKit/UIKitExtensions/UIColor+QMUI.m @@ -170,6 +170,38 @@ - (UIColor *)qmui_transitionToColor:(UIColor *)toColor progress:(CGFloat)progres return [UIColor qmui_colorFromColor:self toColor:toColor progress:progress]; } +- (BOOL)qmui_colorIsDark { + CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; + [self getRed:&red green:&green blue:&blue alpha:&alpha]; + + float referenceValue = 0.411; + float colorDelta = ((red * 0.299) + (green * 0.587) + (blue * 0.114)); + + return 1.0 - colorDelta > referenceValue; +} + +- (UIColor *)qmui_inverseColor { + const CGFloat *componentColors = CGColorGetComponents(self.CGColor); + UIColor *newColor = [[UIColor alloc] initWithRed:(1.0 - componentColors[0]) + green:(1.0 - componentColors[1]) + blue:(1.0 - componentColors[2]) + alpha:componentColors[3]]; + return newColor; +} + +- (BOOL)qmui_isSystemTintColor { + return [self isEqual:[UIColor qmui_systemTintColor]]; +} + ++ (UIColor *)qmui_systemTintColor { + static UIColor *systemTintColor = nil; + if (!systemTintColor) { + UIView *view = [[UIView alloc] init]; + systemTintColor = view.tintColor; + } + return systemTintColor; +} + + (UIColor *)qmui_colorWithBackendColor:(UIColor *)backendColor frontColor:(UIColor *)frontColor { CGFloat bgAlpha = [backendColor qmui_alpha]; CGFloat bgRed = [backendColor qmui_red]; @@ -215,23 +247,4 @@ + (UIColor *)qmui_randomColor { return [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; } -- (BOOL)qmui_colorIsDark { - CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; - [self getRed:&red green:&green blue:&blue alpha:&alpha]; - - float referenceValue = 0.411; - float colorDelta = ((red * 0.299) + (green * 0.587) + (blue * 0.114)); - - return 1.0 - colorDelta > referenceValue; -} - -- (UIColor *)qmui_inverseColor { - const CGFloat *componentColors = CGColorGetComponents(self.CGColor); - UIColor *newColor = [[UIColor alloc] initWithRed:(1.0 - componentColors[0]) - green:(1.0 - componentColors[1]) - blue:(1.0 - componentColors[2]) - alpha:componentColors[3]]; - return newColor; -} - @end diff --git a/QMUIKit/UIKitExtensions/UIFont+QMUI.h b/QMUIKit/UIKitExtensions/UIFont+QMUI.h index b665d493..8f6cd830 100644 --- a/QMUIKit/UIKitExtensions/UIFont+QMUI.h +++ b/QMUIKit/UIKitExtensions/UIFont+QMUI.h @@ -8,11 +8,11 @@ #import -typedef enum : NSUInteger { +typedef NS_ENUM(NSUInteger, QMUIFontWeight) { QMUIFontWeightLight, QMUIFontWeightNormal, QMUIFontWeightBold -} QMUIFontWeight; +}; @interface UIFont (QMUI) diff --git a/QMUIKit/UIKitExtensions/UIImage+QMUI.h b/QMUIKit/UIKitExtensions/UIImage+QMUI.h index 3dc9da76..6b606459 100644 --- a/QMUIKit/UIKitExtensions/UIImage+QMUI.h +++ b/QMUIKit/UIKitExtensions/UIImage+QMUI.h @@ -74,6 +74,17 @@ typedef NS_OPTIONS(NSInteger, QMUIImageBorderPosition) { */ - (UIImage *)qmui_imageWithTintColor:(UIColor *)tintColor; +/** + * 以 CIColorBlendMode 的模式为当前图片叠加一个颜色,生成一张新图片并返回,在叠加过程中会保留图片内的纹理。 + * + * @param blendColor 要叠加的颜色 + * + * @return 基于当前图片纹理保持不变的情况下颜色变为指定的叠加颜色的新图片 + * + * @warning 这个方法可能比较慢,会卡住主线程,建议异步使用 + */ +- (UIImage *)qmui_imageWithBlendColor:(UIColor *)blendColor; + /** * 在当前图片的基础上叠加一张图片,并指定绘制叠加图片的起始位置 * diff --git a/QMUIKit/UIKitExtensions/UIImage+QMUI.m b/QMUIKit/UIKitExtensions/UIImage+QMUI.m index 1f7f28e3..c2341651 100644 --- a/QMUIKit/UIKitExtensions/UIImage+QMUI.m +++ b/QMUIKit/UIKitExtensions/UIImage+QMUI.m @@ -129,6 +129,19 @@ - (UIImage *)qmui_imageWithTintColor:(UIColor *)tintColor { return imageOut; } +- (UIImage *)qmui_imageWithBlendColor:(UIColor *)blendColor { + UIImage *coloredImage = [self qmui_imageWithTintColor:blendColor]; + CIFilter *filter = [CIFilter filterWithName:@"CIColorBlendMode"]; + [filter setValue:[CIImage imageWithCGImage:self.CGImage] forKey:kCIInputBackgroundImageKey]; + [filter setValue:[CIImage imageWithCGImage:coloredImage.CGImage] forKey:kCIInputImageKey]; + CIImage *outputImage = filter.outputImage; + CIContext *context = [CIContext contextWithOptions:nil]; + CGImageRef imageRef = [context createCGImage:outputImage fromRect:outputImage.extent]; + UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; + CGImageRelease(imageRef); + return resultImage; +} + - (UIImage *)qmui_imageWithImageAbove:(UIImage *)image atPoint:(CGPoint)point { UIImage *imageIn = self; UIImage *imageOut = nil; @@ -472,7 +485,7 @@ + (UIImage *)qmui_imageWithShape:(QMUIImageShape)shape size:(CGSize)size lineWid CGContextInspectSize(size); UIImage *resultImage = nil; - tintColor = tintColor ? tintColor : UIColorWhite; + tintColor = tintColor ? : [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; UIGraphicsBeginImageContextWithOptions(size, NO, 0); diff --git a/QMUIKit/UIKitExtensions/UITextView+QMUI.h b/QMUIKit/UIKitExtensions/UITextView+QMUI.h index 0a7cbd0b..7b168b61 100644 --- a/QMUIKit/UIKitExtensions/UITextView+QMUI.h +++ b/QMUIKit/UIKitExtensions/UITextView+QMUI.h @@ -14,6 +14,11 @@ @interface UITextView (QMUI) +/** + * convert UITextRange to NSRange, for example, [self qmui_convertNSRangeFromUITextRange:self.markedTextRange] + */ +- (NSRange)qmui_convertNSRangeFromUITextRange:(UITextRange *)textRange; + /** * 设置 text 会让 selectedTextRange 跳到最后一个字符,导致在中间修改文字后光标会跳到末尾,所以设置前要保存一下,设置后恢复过来 */ @@ -24,6 +29,11 @@ */ - (void)qmui_setAttributedTextKeepingSelectedRange:(NSAttributedString *)attributedText; +/** + * [UITextView scrollRangeToVisible:] 并不会考虑 textContainerInset.bottom,所以使用这个方法来代替 + */ +- (void)qmui_scrollCaretVisibleAnimated:(BOOL)animated; + /// 键盘相关block,搭配QMUIKeyboardManager一起使用 @property(nonatomic, copy) void (^qmui_keyboardWillShowNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo); diff --git a/QMUIKit/UIKitExtensions/UITextView+QMUI.m b/QMUIKit/UIKitExtensions/UITextView+QMUI.m index 2536bd0d..63e4579d 100644 --- a/QMUIKit/UIKitExtensions/UITextView+QMUI.m +++ b/QMUIKit/UIKitExtensions/UITextView+QMUI.m @@ -17,6 +17,12 @@ @interface UITextView () @implementation UITextView (QMUI) +- (NSRange)qmui_convertNSRangeFromUITextRange:(UITextRange *)textRange { + NSInteger location = [self offsetFromPosition:self.beginningOfDocument toPosition:textRange.start]; + NSInteger length = [self offsetFromPosition:textRange.start toPosition:textRange.end]; + return NSMakeRange(location, length); +} + - (void)qmui_setTextKeepingSelectedRange:(NSString *)text { UITextRange *selectedTextRange = self.selectedTextRange; self.text = text; @@ -29,6 +35,26 @@ - (void)qmui_setAttributedTextKeepingSelectedRange:(NSAttributedString *)attribu self.selectedTextRange = selectedTextRange; } +- (void)qmui_scrollCaretVisibleAnimated:(BOOL)animated { + if (CGRectIsEmpty(self.bounds)) { + return; + } + + CGRect caretRect = [self caretRectForPosition:self.selectedTextRange.end]; + CGFloat contentOffsetY = self.contentOffset.y; + if (CGRectGetMinY(caretRect) < self.contentOffset.y + self.textContainerInset.top) { + // 光标在可视区域上方,往下滚动 + contentOffsetY = CGRectGetMinY(caretRect) - self.textContainerInset.top - self.contentInset.top; + } else if (CGRectGetMaxY(caretRect) > self.contentOffset.y + CGRectGetHeight(self.bounds) - self.textContainerInset.bottom - self.contentInset.bottom) { + // 光标在可视区域下方,往上滚动 + contentOffsetY = CGRectGetMaxY(caretRect) - CGRectGetHeight(self.bounds) + self.textContainerInset.bottom + self.contentInset.bottom; + } else { + // 光标在可视区域内,不用调整 + return; + } + [self setContentOffset:CGPointMake(self.contentOffset.x, contentOffsetY) animated:animated]; +} + - (void)setQmui_keyboardWillShowNotificationBlock:(void (^)(QMUIKeyboardUserInfo *))keyboardWillShowNotificationBlock { objc_setAssociatedObject(self, @selector(qmui_keyboardWillShowNotificationBlock), keyboardWillShowNotificationBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); if (keyboardWillShowNotificationBlock) { diff --git a/QMUIKit/UIMainFrame/QMUICommonViewController.m b/QMUIKit/UIMainFrame/QMUICommonViewController.m index 24c51688..4aefb58a 100644 --- a/QMUIKit/UIMainFrame/QMUICommonViewController.m +++ b/QMUIKit/UIMainFrame/QMUICommonViewController.m @@ -39,6 +39,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { - (void)didInitialized { self.titleView = [[QMUINavigationTitleView alloc] init]; + self.titleView.title = self.title;// 从 storyboard 初始化的话,可能带有 self.title 的值 self.hidesBottomBarWhenPushed = HidesBottomBarWhenPushedInitially;