Skip to content

Commit

Permalink
1. 修复 QMUITextView 文字发生变化时光标位置滚动不准确的 bug;
Browse files Browse the repository at this point in the history
2. UITextView (QMUI) 增加 qmui_convertNSRangeFromUITextRange 用于将 UITextPosition 转化为 NSRange;
3. UITextView (QMUI) 增加 qmui_scrollCaretVisibleAnimated: 用于将光标滚动到可视区域并且考虑 textContainerInset;
4. 将 QMUIKit 里的配置表默认值改为 nil,以使默认的样式与系统样式保持一致;
5. 整理几个 QMUI 控件的 initWithCoder: 方法,在里面不要设置能在 IB 里修改的属性,不然会覆盖 IB 的值;
6. 修复在 storyboard 里使用 QMUICommonViewController 并为其设置 title 后,无法显示 title;
7. 统一 enum 的定义方式,兼容 Swift 下的使用;
8. UIImage (QMUI) 增加 qmui_imageWithBlendColor: 方法用户修改图片颜色
  • Loading branch information
MoLice committed May 11, 2017
1 parent 82df0ac commit bfd2a8e
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 298 deletions.
4 changes: 1 addition & 3 deletions QMUIConfigurationTemplate/QMUIConfigurationTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
252 changes: 125 additions & 127 deletions QMUIConfigurationTemplate/QMUIConfigurationTemplate.m

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions QMUIKit/UICommon/QMUIConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
120 changes: 75 additions & 45 deletions QMUIKit/UICommon/QMUIConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -223,6 +229,7 @@ - (void)setNavBarTitleFont:(UIFont *)navBarTitleFont {
[titleTextAttributes setValue:self.navBarTitleColor forKey:NSForegroundColorAttributeName];
}
[UINavigationBar appearance].titleTextAttributes = titleTextAttributes;
[QMUIHelper visibleViewController].navigationController.navigationBar.titleTextAttributes = titleTextAttributes;
}
}

Expand All @@ -237,6 +244,7 @@ - (void)setNavBarTitleColor:(UIColor *)navBarTitleColor {
[titleTextAttributes setValue:self.navBarTitleColor forKey:NSForegroundColorAttributeName];
}
[UINavigationBar appearance].titleTextAttributes = titleTextAttributes;
[QMUIHelper visibleViewController].navigationController.navigationBar.titleTextAttributes = titleTextAttributes;
}
}

Expand All @@ -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上实际测量得到
Expand All @@ -259,6 +268,8 @@ - (void)setNavBarBackIndicatorImage:(UIImage *)navBarBackIndicatorImage {

navBarAppearance.backIndicatorImage = _navBarBackIndicatorImage;
navBarAppearance.backIndicatorTransitionMaskImage = navBarAppearance.backIndicatorImage;
navigationBar.backIndicatorImage = _navBarBackIndicatorImage;
navigationBar.backIndicatorTransitionMaskImage = navigationBar.backIndicatorImage;
}
}

Expand All @@ -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<NSString *, id> *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<NSString *, id> *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];
}];
}
}

Expand Down
2 changes: 0 additions & 2 deletions QMUIKit/UICommon/QMUIConfigurationMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@

#import <Photos/PHImageManager.h>

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;
Expand Down
Loading

0 comments on commit bfd2a8e

Please sign in to comment.