Commit c9ab3f78 cgx

登录页面UI

1 个父辈 6c756bce
正在显示 48 个修改的文件 包含 1388 行增加143 行删除
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
D0506B1B2805500E00229278 /* SafeHelperCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */; }; D0506B1B2805500E00229278 /* SafeHelperCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */; };
D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */ = {isa = PBXBuildFile; fileRef = D070509928071BAF006D72E1 /* DSNetworkTool.m */; }; D070509A28071BAF006D72E1 /* DSNetworkTool.m in Sources */ = {isa = PBXBuildFile; fileRef = D070509928071BAF006D72E1 /* DSNetworkTool.m */; };
D07F9DE927F4683B0036372F /* DKColorTable.txt in Resources */ = {isa = PBXBuildFile; fileRef = D07F9DE827F4683B0036372F /* DKColorTable.txt */; }; D07F9DE927F4683B0036372F /* DKColorTable.txt in Resources */ = {isa = PBXBuildFile; fileRef = D07F9DE827F4683B0036372F /* DKColorTable.txt */; };
D0878F48280BD18F005F1B7F /* LoginView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0878F47280BD18F005F1B7F /* LoginView.m */; };
D0878F4C280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D0878F4B280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m */; };
D0878F4F280C087E005F1B7F /* LoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0878F4E280C087E005F1B7F /* LoginController.m */; };
D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBB62808F9DA00487A50 /* BreathTextView.m */; }; D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBB62808F9DA00487A50 /* BreathTextView.m */; };
D091BBBB2809079600487A50 /* NSString+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBBA2809079600487A50 /* NSString+Extras.m */; }; D091BBBB2809079600487A50 /* NSString+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D091BBBA2809079600487A50 /* NSString+Extras.m */; };
D0930F122801124E006B497A /* BaseNaviController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F112801124E006B497A /* BaseNaviController.m */; }; D0930F122801124E006B497A /* BaseNaviController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F112801124E006B497A /* BaseNaviController.m */; };
...@@ -129,6 +132,12 @@ ...@@ -129,6 +132,12 @@
D070509928071BAF006D72E1 /* DSNetworkTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkTool.m; sourceTree = "<group>"; }; D070509928071BAF006D72E1 /* DSNetworkTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkTool.m; sourceTree = "<group>"; };
D07F9D0627F45CB20036372F /* DKNightVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DKNightVersion.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D07F9D0627F45CB20036372F /* DKNightVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DKNightVersion.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D07F9DE827F4683B0036372F /* DKColorTable.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DKColorTable.txt; sourceTree = "<group>"; }; D07F9DE827F4683B0036372F /* DKColorTable.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DKColorTable.txt; sourceTree = "<group>"; };
D0878F46280BD18F005F1B7F /* LoginView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginView.h; sourceTree = "<group>"; };
D0878F47280BD18F005F1B7F /* LoginView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginView.m; sourceTree = "<group>"; };
D0878F4A280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+YBAttributeTextTapAction.h"; sourceTree = "<group>"; };
D0878F4B280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+YBAttributeTextTapAction.m"; sourceTree = "<group>"; };
D0878F4D280C087E005F1B7F /* LoginController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginController.h; sourceTree = "<group>"; };
D0878F4E280C087E005F1B7F /* LoginController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginController.m; sourceTree = "<group>"; };
D091BBB52808F9DA00487A50 /* BreathTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BreathTextView.h; sourceTree = "<group>"; }; D091BBB52808F9DA00487A50 /* BreathTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BreathTextView.h; sourceTree = "<group>"; };
D091BBB62808F9DA00487A50 /* BreathTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BreathTextView.m; sourceTree = "<group>"; }; D091BBB62808F9DA00487A50 /* BreathTextView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BreathTextView.m; sourceTree = "<group>"; };
D091BBB82809024100487A50 /* DreamSleepBeta.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DreamSleepBeta.entitlements; sourceTree = "<group>"; }; D091BBB82809024100487A50 /* DreamSleepBeta.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DreamSleepBeta.entitlements; sourceTree = "<group>"; };
...@@ -358,6 +367,7 @@ ...@@ -358,6 +367,7 @@
D04567AD27F6D0F4009F0A82 /* Profile */ = { D04567AD27F6D0F4009F0A82 /* Profile */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D0CE3D80280A532D00D8B02D /* UserLogin */,
D04B3DBC27F6F8090022F8DF /* Profile.storyboard */, D04B3DBC27F6F8090022F8DF /* Profile.storyboard */,
D04B3DBE27F6F82D0022F8DF /* ProfileController.h */, D04B3DBE27F6F82D0022F8DF /* ProfileController.h */,
D04B3DBF27F6F82D0022F8DF /* ProfileController.m */, D04B3DBF27F6F82D0022F8DF /* ProfileController.m */,
...@@ -369,6 +379,15 @@ ...@@ -369,6 +379,15 @@
path = Profile; path = Profile;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D0878F49280BEFF9005F1B7F /* YBAttributeTextTapAction */ = {
isa = PBXGroup;
children = (
D0878F4A280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.h */,
D0878F4B280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m */,
);
path = YBAttributeTextTapAction;
sourceTree = "<group>";
};
D0930F142801874B006B497A /* DSNavigationTools */ = { D0930F142801874B006B497A /* DSNavigationTools */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -458,6 +477,17 @@ ...@@ -458,6 +477,17 @@
path = PrivacyPolicy; path = PrivacyPolicy;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D0CE3D80280A532D00D8B02D /* UserLogin */ = {
isa = PBXGroup;
children = (
D0878F46280BD18F005F1B7F /* LoginView.h */,
D0878F47280BD18F005F1B7F /* LoginView.m */,
D0878F4D280C087E005F1B7F /* LoginController.h */,
D0878F4E280C087E005F1B7F /* LoginController.m */,
);
path = UserLogin;
sourceTree = "<group>";
};
D0E65FF32807A654006562F2 /* HYBUnicodeReadable */ = { D0E65FF32807A654006562F2 /* HYBUnicodeReadable */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -477,6 +507,7 @@ ...@@ -477,6 +507,7 @@
D01814D927FFD91100583D4E /* DataSource */, D01814D927FFD91100583D4E /* DataSource */,
D01814CA27FFCBAF00583D4E /* CWCarousel */, D01814CA27FFCBAF00583D4E /* CWCarousel */,
D0E65FF32807A654006562F2 /* HYBUnicodeReadable */, D0E65FF32807A654006562F2 /* HYBUnicodeReadable */,
D0878F49280BEFF9005F1B7F /* YBAttributeTextTapAction */,
D0E9408227FE96A900D57495 /* WechatOpenSDK_1.9.2_NoPay */, D0E9408227FE96A900D57495 /* WechatOpenSDK_1.9.2_NoPay */,
); );
path = Vendors; path = Vendors;
...@@ -726,10 +757,12 @@ ...@@ -726,10 +757,12 @@
D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */, D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */,
D0C50B4627FD66FB00DC68F0 /* DSConstUtil.m in Sources */, D0C50B4627FD66FB00DC68F0 /* DSConstUtil.m in Sources */,
D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */, D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */,
D0878F48280BD18F005F1B7F /* LoginView.m in Sources */,
D0E660052807D02C006562F2 /* UserRequestModel.m in Sources */, D0E660052807D02C006562F2 /* UserRequestModel.m in Sources */,
D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */, D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */,
D0506B1528051ED400229278 /* SafeSleepModel.m in Sources */, D0506B1528051ED400229278 /* SafeSleepModel.m in Sources */,
D01814D527FFCCFA00583D4E /* HomeTableView.m in Sources */, D01814D527FFCCFA00583D4E /* HomeTableView.m in Sources */,
D0878F4C280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m in Sources */,
D0F80907280431100097899F /* UILabel+Extras.m in Sources */, D0F80907280431100097899F /* UILabel+Extras.m in Sources */,
D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */, D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */,
D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */, D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */,
...@@ -746,6 +779,7 @@ ...@@ -746,6 +779,7 @@
D0E65FFC2807A654006562F2 /* NSSet+HYBUnicodeReadable.m in Sources */, D0E65FFC2807A654006562F2 /* NSSet+HYBUnicodeReadable.m in Sources */,
D0C50B3C27FD2EFD00DC68F0 /* PrivacyViewController.m in Sources */, D0C50B3C27FD2EFD00DC68F0 /* PrivacyViewController.m in Sources */,
D0930F122801124E006B497A /* BaseNaviController.m in Sources */, D0930F122801124E006B497A /* BaseNaviController.m in Sources */,
D0878F4F280C087E005F1B7F /* LoginController.m in Sources */,
D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */, D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */,
D0F808FE280421C20097899F /* ThreeMinuteController.m in Sources */, D0F808FE280421C20097899F /* ThreeMinuteController.m in Sources */,
D01814E8280020F900583D4E /* CWPageControl.m in Sources */, D01814E8280020F900583D4E /* CWPageControl.m in Sources */,
...@@ -923,7 +957,7 @@ ...@@ -923,7 +957,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay", "$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay",
); );
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.1.0;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-Objc", "-Objc",
...@@ -957,7 +991,7 @@ ...@@ -957,7 +991,7 @@
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)/**"; HEADER_SEARCH_PATHS = "$(inherited)/**";
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist; INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠-Dev"; INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIStatusBarHidden = YES; INFOPLIST_KEY_UIStatusBarHidden = YES;
...@@ -972,7 +1006,7 @@ ...@@ -972,7 +1006,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay", "$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay",
); );
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.1.0;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-Objc", "-Objc",
...@@ -1064,7 +1098,7 @@ ...@@ -1064,7 +1098,7 @@
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)/**"; HEADER_SEARCH_PATHS = "$(inherited)/**";
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist; INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠-Dev"; INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠-Beta";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIStatusBarHidden = YES; INFOPLIST_KEY_UIStatusBarHidden = YES;
...@@ -1079,7 +1113,7 @@ ...@@ -1079,7 +1113,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay", "$(PROJECT_DIR)/DreamSleep/Vendors/WechatOpenSDK_1.9.2_NoPay",
); );
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.1.0;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-Objc", "-Objc",
......
...@@ -32,6 +32,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -32,6 +32,10 @@ NS_ASSUME_NONNULL_BEGIN
* @param sizeToFit 是否按尺寸调整 * @param sizeToFit 是否按尺寸调整
*/ */
- (void)adjustLayoutWithType:(UIButtonLayoutType)type midSpace:(CGFloat)midSpace sizeToFit:(BOOL)sizeToFit; - (void)adjustLayoutWithType:(UIButtonLayoutType)type midSpace:(CGFloat)midSpace sizeToFit:(BOOL)sizeToFit;
+ (instancetype)btnWithTitle:(NSString *)title titleColor:(UIColor *)titleColor font:(UIFont *)font bgColor:(UIColor *)bgColor;
+ (instancetype)btnWithTitle:(NSString *)title font:(UIFont *)font;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -55,4 +55,20 @@ ...@@ -55,4 +55,20 @@
[self setImageEdgeInsets:imageEdgeInset]; [self setImageEdgeInsets:imageEdgeInset];
} }
+ (instancetype)btnWithTitle:(NSString *)title titleColor:(UIColor *)titleColor font:(UIFont *)font bgColor:(UIColor *)bgColor {
UIButton *btn = [UIButton new];
[btn setTitle:title forState:UIControlStateNormal];
[btn setTitleColor:titleColor forState:UIControlStateNormal];
[btn.titleLabel setFont:font];
[btn setBackgroundColor:bgColor];
return btn;
}
+ (instancetype)btnWithTitle:(NSString *)title font:(UIFont *)font {
UIButton *btn = [UIButton new];
[btn setTitle:title forState:UIControlStateNormal];
[btn.titleLabel setFont:font];
return btn;
}
@end @end
...@@ -23,5 +23,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -23,5 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
- (UIViewController *)ds_viewController; - (UIViewController *)ds_viewController;
- (void)debugViewShowBorder; - (void)debugViewShowBorder;
- (void)cornerRadius:(CGFloat)radius;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -68,4 +68,9 @@ ...@@ -68,4 +68,9 @@
self.layer.borderWidth = 2; self.layer.borderWidth = 2;
} }
- (void)cornerRadius:(CGFloat)radius {
self.layer.cornerRadius = radius;
self.layer.masksToBounds = YES;
}
@end @end
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#import "HeaderDataModel.h" #import "HeaderDataModel.h"
#import "ThreeMinuteController.h" #import "ThreeMinuteController.h"
#import "BreatheController.h" #import "BreatheController.h"
#import "WXApi.h"
@interface DsMiddleView () @interface DsMiddleView ()
@property (nonatomic, strong) UIButton *unityBtn; @property (nonatomic, strong) UIButton *unityBtn;
...@@ -78,16 +77,6 @@ ...@@ -78,16 +77,6 @@
breatheVC.title = sender.tag == 1 ? @"均衡呼吸法" : @"舒睡4-7-8呼吸法"; breatheVC.title = sender.tag == 1 ? @"均衡呼吸法" : @"舒睡4-7-8呼吸法";
[self.ds_viewController.navigationController pushViewController:breatheVC animated:YES]; [self.ds_viewController.navigationController pushViewController:breatheVC animated:YES];
} }
#pragma mark - 模拟微信登录
// // 构造SendAuthReq结构体
// SendAuthReq* req = [[SendAuthReq alloc] init];
// req.scope = @"snsapi_userinfo";
// req.state = @"123";
// // 第三方向微信终端发送一个SendAuthReq消息结构
// [WXApi sendReq:req completion:^(BOOL success) {
// DSLog(@"调起微信成功...");
// }];
} }
@end @end
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
- (UIButton *)timerBtn { - (UIButton *)timerBtn {
if (!_timerBtn) { if (!_timerBtn) {
_timerBtn = [UIButton new]; _timerBtn = [UIButton new];
[_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk") forState:UIControlStateNormal]; [_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk", @"timerIcon_dk") forState:UIControlStateNormal];
[_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside]; [_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside];
} }
return _timerBtn; return _timerBtn;
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
// 切换到主tabvc // 切换到主tabvc
UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
[UIView transitionWithView:DSKeyWindow [UIView transitionWithView:DSKeyWindow
duration:0.3 duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ animations:^{
DSKeyWindow.rootViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"mainSB"]; DSKeyWindow.rootViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"mainSB"];
......
...@@ -38,12 +38,12 @@ ...@@ -38,12 +38,12 @@
titleColor = ColorFromHex(0x333333); titleColor = ColorFromHex(0x333333);
bgColor = DSWhite; bgColor = DSWhite;
barTintColor = DSWhite; barTintColor = DSWhite;
// naviBar.barStyle = UIBarStyleDefault; // naviBar.barStyle = UIBarStyleDefault;
} else if (style == NaviStyleDark) { } else if (style == NaviStyleDark) {
titleColor = DSWhite; titleColor = DSWhite;
bgColor = DarkColor; bgColor = DarkColor;
barTintColor = DarkColor; barTintColor = DarkColor;
// naviBar.barStyle = UIBarStyleBlack; // naviBar.barStyle = UIBarStyleBlack;
} }
// 设置导航栏title颜色、导航栏背景色、隐藏分割线 // 设置导航栏title颜色、导航栏背景色、隐藏分割线
...@@ -95,7 +95,11 @@ ...@@ -95,7 +95,11 @@
UIViewController* topVC = self.topViewController; UIViewController* topVC = self.topViewController;
if ([topVC respondsToSelector:@selector(navigationBarStyle)]) { if ([topVC respondsToSelector:@selector(navigationBarStyle)]) {
NaviStyle sty = (NaviStyle)[topVC performSelector:@selector(navigationBarStyle)]; NaviStyle sty = (NaviStyle)[topVC performSelector:@selector(navigationBarStyle)];
if (sty == NaviStyleDefault) { barStyle = UIStatusBarStyleLightContent; } if (sty == NaviStyleDefault) {
barStyle = UIStatusBarStyleLightContent;
} else if (sty == NaviStyleDark) {
barStyle = UIStatusBarStyleLightContent;
}
} }
return barStyle; return barStyle;
} }
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#import "ProfileController.h" #import "ProfileController.h"
#import "SystemSetController.h" #import "SystemSetController.h"
#import <AuthenticationServices/AuthenticationServices.h> #import "LoginController.h"
@interface ProfileController () <ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding> @interface ProfileController ()
@property (nonatomic, strong) NSArray *tmpDatas; @property (nonatomic, strong) NSArray *tmpDatas;
@end @end
...@@ -20,12 +20,17 @@ ...@@ -20,12 +20,17 @@
self.navigationItem.title = @"我的"; self.navigationItem.title = @"我的";
self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.tmpDatas = @[@"注册登录信息", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法", @"模拟Apple登录"]; self.tmpDatas = @[@"注册登录信息", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法"];
} }
#pragma mark - 导航栏默认模式 #pragma mark - 导航栏默认模式
//- (NaviStyle)navigationBarStyle {
// return NaviStyleDefault;
//}
#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle { - (NaviStyle)navigationBarStyle {
return NaviStyleDefault; return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
} }
#pragma mark - Table view data source #pragma mark - Table view data source
...@@ -46,15 +51,16 @@ ...@@ -46,15 +51,16 @@
[tableView deselectRowAtIndexPath:indexPath animated:YES]; [tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.row) { switch (indexPath.row) {
case 2: // 系统设置入口 case 0: // 跳转到登录页面
{ {
SystemSetController *sysVC = [SystemSetController new]; BaseNaviController *navi = [[BaseNaviController alloc] initWithRootViewController:[[LoginController alloc] init]];
[self.navigationController pushViewController:sysVC animated:YES]; [self presentViewController:navi animated:YES completion:nil];
} }
break; break;
case 9: // 模拟苹果登录 case 2: // 系统设置入口
{ {
[self handleAuthrization]; SystemSetController *sysVC = [SystemSetController new];
[self.navigationController pushViewController:sysVC animated:YES];
} }
break; break;
default: default:
...@@ -62,116 +68,4 @@ ...@@ -62,116 +68,4 @@
} }
} }
#pragma mark - 点击苹果登录授权按钮
- (void)handleAuthrization {
if (@available(iOS 13.0, *)) {
// 基于用户的Apple ID授权用户,生成用户授权请求的一种机制
ASAuthorizationAppleIDProvider *appleIDProvider = [ASAuthorizationAppleIDProvider new];
// 创建新的AppleID 授权请求
ASAuthorizationAppleIDRequest *request = appleIDProvider.createRequest;
// 在用户授权期间请求的联系信息
request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
// 由ASAuthorizationAppleIDProvider创建的授权请求 管理授权请求的控制器
ASAuthorizationController *controller = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
// 设置授权控制器通知授权请求的成功与失败的代理
controller.delegate = self;
// 设置提供 展示上下文的代理,在这个上下文中 系统可以展示授权界面给用户
controller.presentationContextProvider = self;
// 在控制器初始化期间启动授权流
[controller performRequests];
}
}
#pragma mark - ASAuthorizationControllerDelegate
#pragma mark - 授权成功地回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"%@", controller);
NSLog(@"%@", authorization);
NSLog(@"authorization.credential:%@", authorization.credential);
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential *credential = authorization.credential;
NSLog(@"credential = %@", credential);
NSString *state = credential.state;
NSString *userID = credential.user;
NSPersonNameComponents *fullName = credential.fullName;
NSString *email = credential.email;
NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding]; // 验证 token
NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding]; // 用户 token
ASUserDetectionStatus realUserStatus = credential.realUserStatus;
NSArray *authorizedScopes = credential.authorizedScopes;
NSLog(@"ios登陆成功 state: %@\nuserID: %@\nfullName: %@\nemail: %@\nauthorizationCode: %@\nidentityToken: %@\nrealUserStatus: %@\nauthorizedScopes: %@",
state,
userID,
fullName,
email,
authorizationCode,
identityToken,
@(realUserStatus),
authorizedScopes);
// // 用户登录使用ASAuthorizationAppleIDCredential
// ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
// // 用户ID: user,苹果用户唯一标识,该值在同一个开发者账号下的所有 App 下是一样的。
// NSString *user = appleIDCredential.user;
// // 使用钥匙串的方式保存用户的唯一信息
// NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
//
// // 验证数据: identityToken , authorizationCode ,用于服务端验证授权请求的合法性。
// NSString *authorizationCode = [[NSString alloc] initWithData:appleIDCredential.authorizationCode encoding:NSUTF8StringEncoding];
// NSString *identityToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding];
//
// NSLog(@"user:%@, bundleId:%@, authorizationCode:%@, identityToken:%@", user, bundleId, authorizationCode, identityToken);
// 通过钥匙串保存用户授权信息
// [SAMKeychain setPassword:user forService:bundleId account:ShareCurrentIdentifier];
} else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) {
// 用户登录使用现有的密码凭证
ASPasswordCredential *passwordCredential = authorization.credential;
// 密码凭证对象的用户标识 用户的唯一标识
NSString *user = passwordCredential.user;
// 密码凭证对象的密码
NSString *password = passwordCredential.password;
NSLog(@"user:%@, password:%@", user, password);
} else {
NSLog(@"授权信息均不符");
}
}
#pragma mark - 授权失败的回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"错误信息:%@", error);
NSString *errorMsg = nil;
switch (error.code) {
case ASAuthorizationErrorCanceled:
errorMsg = @"用户取消了授权请求";
break;
case ASAuthorizationErrorFailed:
errorMsg = @"授权请求失败";
break;
case ASAuthorizationErrorInvalidResponse:
errorMsg = @"授权请求响应无效";
break;
case ASAuthorizationErrorNotHandled:
errorMsg = @"未能处理授权请求";
break;
case ASAuthorizationErrorUnknown:
errorMsg = @"授权请求失败未知原因";
break;
}
NSLog(@"controller requests:%@, errorMsg:%@", controller.authorizationRequests, errorMsg);
}
#pragma mark - ASAuthorizationControllerPresentationContextProviding
#pragma mark - 告诉代理应该在哪个window 展示内容给用户
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)){
NSLog(@"调用展示window方法:%s", __FUNCTION__);
// 返回window
return self.view.window;
}
@end @end
...@@ -22,16 +22,24 @@ ...@@ -22,16 +22,24 @@
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 100, 100, 40)]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 100, 100, 40)];
[btn setTitle:@"用户协议" forState:UIControlStateNormal]; [btn setTitle:@"用户协议" forState:UIControlStateNormal];
[btn debugViewShowBorder];
[btn setTitleColor:DSRed forState:UIControlStateNormal]; [btn setTitleColor:DSRed forState:UIControlStateNormal];
[btn addTarget:self action:@selector(privicyAction) forControlEvents:UIControlEventTouchUpInside]; [btn addTarget:self action:@selector(privicyAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; [self.view addSubview:btn];
UIButton *darkBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200, 100, 40)];
[darkBtn setTitle:@"黑夜模式" forState:UIControlStateNormal];
[darkBtn debugViewShowBorder];
[darkBtn setTitleColor:DSRed forState:UIControlStateNormal];
[darkBtn addTarget:self action:@selector(darkBtnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:darkBtn];
} }
- (void)privicyAction { - (void)privicyAction {
[self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"用户协议" link:[NSURL URLWithString:UserServiceAgreement] isDetail:YES] animated:YES]; [self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"用户协议" link:[NSURL URLWithString:UserServiceAgreement] isDetail:YES] animated:YES];
} }
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { - (void)darkBtnAction {
// 模拟切换黑夜模式 // 模拟切换黑夜模式
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
self.dk_manager.themeVersion = DKThemeVersionNormal; self.dk_manager.themeVersion = DKThemeVersionNormal;
......
//
// LoginController.h
// DreamSleep
//
// Created by peter on 2022/4/17.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface LoginController : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// LoginController.m
// DreamSleep
//
// Created by peter on 2022/4/17.
//
#import "LoginController.h"
#import "LoginView.h"
#import "PrivacyViewController.h"
#import <AuthenticationServices/AuthenticationServices.h>
@interface LoginController () <LoginViewDelegate, ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
@property (strong, nonatomic) LoginView *loginView;
@end
@implementation LoginController
- (void)loadView {
self.view = self.loginView;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
#pragma mark - 设置状态栏文字颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
}
#pragma mark - LoginViewDelegate
- (void)sendClickAction:(NSInteger)tag {
switch (tag) {
case 1: // 微信登录
{
// 构造SendAuthReq结构体
SendAuthReq* req = [[SendAuthReq alloc] init];
req.scope = @"snsapi_userinfo";
req.state = @"123";
// 第三方向微信终端发送一个SendAuthReq消息结构
[WXApi sendReq:req completion:^(BOOL success) {
DSLog(@"调起微信成功...");
}];
}
break;
case 2: // Apple登录
{
if (@available(iOS 13.0, *)) {
// 基于用户的Apple ID授权用户,生成用户授权请求的一种机制
ASAuthorizationAppleIDProvider *appleIDProvider = [ASAuthorizationAppleIDProvider new];
// 创建新的AppleID 授权请求
ASAuthorizationAppleIDRequest *request = appleIDProvider.createRequest;
// 在用户授权期间请求的联系信息
request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
// 由ASAuthorizationAppleIDProvider创建的授权请求 管理授权请求的控制器
ASAuthorizationController *controller = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
// 设置授权控制器通知授权请求的成功与失败的代理
controller.delegate = self;
// 设置提供 展示上下文的代理,在这个上下文中 系统可以展示授权界面给用户
controller.presentationContextProvider = self;
// 在控制器初始化期间启动授权流
[controller performRequests];
}
}
break;
case 3: // 随便看看
{
[self dismissViewControllerAnimated:YES completion:nil];
}
break;
case 4: // 许可协议
{
[self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"用户服务协议" link:[NSURL URLWithString:UserServiceAgreement] isDetail:YES] animated:YES];
}
break;
case 5: // 隐私保护指引
{
[self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"隐私政策" link:[NSURL URLWithString:PrivacyPolicy] isDetail:YES] animated:YES];
}
break;
default:
break;
}
}
#pragma mark - ASAuthorizationControllerDelegate
#pragma mark - 授权成功地回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"%@", controller);
NSLog(@"%@", authorization);
NSLog(@"authorization.credential:%@", authorization.credential);
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential *credential = authorization.credential;
NSLog(@"credential = %@", credential);
NSString *state = credential.state;
NSString *userID = credential.user;
NSPersonNameComponents *fullName = credential.fullName;
NSString *email = credential.email;
NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding]; // 验证 token
NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding]; // 用户 token
ASUserDetectionStatus realUserStatus = credential.realUserStatus;
NSArray *authorizedScopes = credential.authorizedScopes;
NSLog(@"ios登陆成功 state: %@\nuserID: %@\nfullName: %@\nemail: %@\nauthorizationCode: %@\nidentityToken: %@\nrealUserStatus: %@\nauthorizedScopes: %@",
state,
userID,
fullName,
email,
authorizationCode,
identityToken,
@(realUserStatus),
authorizedScopes);
// // 用户登录使用ASAuthorizationAppleIDCredential
// ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
// // 用户ID: user,苹果用户唯一标识,该值在同一个开发者账号下的所有 App 下是一样的。
// NSString *user = appleIDCredential.user;
// // 使用钥匙串的方式保存用户的唯一信息
// NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
//
// // 验证数据: identityToken , authorizationCode ,用于服务端验证授权请求的合法性。
// NSString *authorizationCode = [[NSString alloc] initWithData:appleIDCredential.authorizationCode encoding:NSUTF8StringEncoding];
// NSString *identityToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding];
//
// NSLog(@"user:%@, bundleId:%@, authorizationCode:%@, identityToken:%@", user, bundleId, authorizationCode, identityToken);
// 通过钥匙串保存用户授权信息
// [SAMKeychain setPassword:user forService:bundleId account:ShareCurrentIdentifier];
} else if ([authorization.credential isKindOfClass:[ASPasswordCredential class]]) {
// 用户登录使用现有的密码凭证
ASPasswordCredential *passwordCredential = authorization.credential;
// 密码凭证对象的用户标识 用户的唯一标识
NSString *user = passwordCredential.user;
// 密码凭证对象的密码
NSString *password = passwordCredential.password;
NSLog(@"user:%@, password:%@", user, password);
} else {
NSLog(@"授权信息均不符");
}
}
#pragma mark - 授权失败的回调
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) {
NSLog(@"%s", __FUNCTION__);
NSLog(@"错误信息:%@", error);
NSString *errorMsg = nil;
switch (error.code) {
case ASAuthorizationErrorCanceled:
errorMsg = @"用户取消了授权请求";
break;
case ASAuthorizationErrorFailed:
errorMsg = @"授权请求失败";
break;
case ASAuthorizationErrorInvalidResponse:
errorMsg = @"授权请求响应无效";
break;
case ASAuthorizationErrorNotHandled:
errorMsg = @"未能处理授权请求";
break;
case ASAuthorizationErrorUnknown:
errorMsg = @"授权请求失败未知原因";
break;
}
NSLog(@"controller requests:%@, errorMsg:%@", controller.authorizationRequests, errorMsg);
}
#pragma mark - ASAuthorizationControllerPresentationContextProviding
#pragma mark - 告诉代理应该在哪个window 展示内容给用户
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)){
NSLog(@"调用展示window方法:%s", __FUNCTION__);
// 返回window
return self.view.window;
}
- (LoginView *)loginView {
if (!_loginView) {
_loginView = [[LoginView alloc] initWithDelegate:self];
}
return _loginView;
}
@end
//
// LoginView.h
// DreamSleep
//
// Created by peter on 2022/4/17.
//
#import <UIKit/UIKit.h>
#import "WXApi.h"
NS_ASSUME_NONNULL_BEGIN
@protocol LoginViewDelegate <NSObject>
- (void)sendClickAction:(NSInteger)tag;
@end
@interface LoginView : UIView
@property (nonatomic, weak) id<LoginViewDelegate> delegate;
- (instancetype)initWithDelegate:(id<LoginViewDelegate>)delegate;
/// 根据后台接口显示/隐藏苹果登录按钮并更新约束
/// @param state BOOL
- (void)updateAppleLoginState:(BOOL)state;
@end
NS_ASSUME_NONNULL_END
//
// LoginView.m
// DreamSleep
//
// Created by peter on 2022/4/17.
//
#import "LoginView.h"
#import "UILabel+YBAttributeTextTapAction.h"
@interface LoginView ()
@property (strong, nonatomic) UILabel *helloLab;
@property (strong, nonatomic) UIImageView *bgIV;
@property (strong, nonatomic) UIButton *wxBtn;
@property (strong, nonatomic) UIButton *appleBtn;
@property (strong, nonatomic) UIButton *randomBtn;
@property (strong, nonatomic) UIButton *agreeBtn;
@end
@implementation LoginView
- (instancetype)initWithDelegate:(id<LoginViewDelegate>)delegate {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)]) {
self.delegate = delegate;
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self addSubview:self.helloLab];
[self addSubview:self.bgIV];
[self addSubview:self.wxBtn];
[self addSubview:self.appleBtn];
[self addSubview:self.randomBtn];
[self addSubview:self.agreeBtn];
[self setConstrait];
}
return self;
}
- (void)setConstrait {
CGFloat helloLab_topMargin = 30;
CGFloat bg_topMargin = -50;
CGFloat wx_topMargin = 0;
CGFloat ran_topMargin = 17;
CGFloat agree_topMargin = 17;
if (is_iPhoneX_series()) {
helloLab_topMargin = 81;
bg_topMargin = -40;
wx_topMargin = 28;
ran_topMargin = 26;
agree_topMargin = 22;
} else if (iPhone6P) {
wx_topMargin = 28;
}
[self.helloLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(30);
make.top.equalTo(self).offset(helloLab_topMargin);
}];
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(0);
make.top.equalTo(self.helloLab.mas_bottom).offset(bg_topMargin);
make.right.equalTo(self).offset(0);
if (iPhone5) { make.height.equalTo(@340); }
}];
[self.wxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgIV.mas_bottom).offset(wx_topMargin);
make.centerX.equalTo(self);
make.width.equalTo(@206);
make.height.equalTo(@40);
}];
[self.wxBtn cornerRadius:20];
[self.appleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// 未安装微信需要隐藏
if (![WXApi isWXAppInstalled]) {
self.wxBtn.hidden = YES;
make.top.equalTo(self.bgIV.mas_bottom).offset(wx_topMargin);
} else {
make.top.equalTo(self.wxBtn.mas_bottom).offset(17);
}
make.centerX.equalTo(self);
make.size.equalTo(self.wxBtn);
}];
[self.appleBtn cornerRadius:20];
[self.randomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.appleBtn.mas_bottom).offset(ran_topMargin);
make.centerX.equalTo(self);
}];
[self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.randomBtn.mas_bottom).offset(agree_topMargin);
make.centerX.equalTo(self);
make.width.equalTo(@(kScreenWidth - 10));
}];
}
- (void)btnAction:(UIButton *)sender {
// 微信和苹果登录按钮
if (sender.tag == 1 || sender.tag == 2) {
if (!self.agreeBtn.selected) {
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = .3;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[self.agreeBtn.layer addAnimation:animation forKey:nil];
return;
}
}
[self sendClickMehodWithTag:(int)sender.tag];
}
- (void)sendClickMehodWithTag:(NSInteger)tag {
if (self.delegate && [self.delegate respondsToSelector:@selector(sendClickAction:)]) {
[self.delegate sendClickAction:tag];
}
}
- (void)onButtonClickAction:(UIButton *)sender {
sender.selected = !sender.selected;
}
- (void)updateAppleLoginState:(BOOL)state {
// 这里写更新逻辑
}
- (UILabel *)helloLab {
if (!_helloLab) {
_helloLab = [UILabel new];
NSString *string = @"您好,\n欢迎来到小梦睡眠";
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:10];
[attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
[attStr addAttribute:NSFontAttributeName value:BoldFont(24) range:NSMakeRange(0, 3)];
[attStr addAttribute:NSFontAttributeName value:SysFont(15) range:NSMakeRange(3, string.length - 3)];
[_helloLab setAttributedText:attStr];
_helloLab.dk_textColorPicker = DKColorPickerWithKey(TEXT);
_helloLab.numberOfLines = 0;
[_helloLab sizeToFit];
}
return _helloLab;
}
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"bg_login_normal", @"bg_login_normal_dk", @"bg_login_normal_dk")];
_bgIV.contentMode = UIViewContentModeScaleAspectFill;
}
return _bgIV;
}
- (UIButton *)wxBtn {
if (!_wxBtn) {
_wxBtn = [UIButton btnWithTitle:@"微信账号登录" titleColor:DSWhite font:BoldFont(16) bgColor:BrandColor];
[_wxBtn setImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
_wxBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 0);
_wxBtn.tag = 1;
[_wxBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _wxBtn;
}
- (UIButton *)appleBtn {
if (!_appleBtn) {
_appleBtn = [UIButton btnWithTitle:@"Apple ID登录" font:BoldFont(16)];
_appleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 0);
_appleBtn.dk_backgroundColorPicker = DKColorPickerWithKey(TEXT);
[_appleBtn dk_setTitleColorPicker:DKColorPickerWithKey(APPLE_TEXT) forState:UIControlStateNormal];
[_appleBtn dk_setImage:DKImagePickerWithNames(@"ic_apple_login", @"ic_apple_login_dk", @"ic_apple_login_dk") forState:UIControlStateNormal];
_appleBtn.tag = 2;
[_appleBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _appleBtn;
}
- (UIButton *)randomBtn {
if (!_randomBtn) {
_randomBtn = [UIButton btnWithTitle:@"不登录,随便看看" titleColor:ColorFromHex(0xAAAAAA) font:SysFont(16) bgColor:DSClearColor];
[_randomBtn sizeToFit];
_randomBtn.tag = 3;
[_randomBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _randomBtn;
}
- (UIButton *)agreeBtn {
if (!_agreeBtn) {
_agreeBtn = [UIButton new];
[_agreeBtn setImage:[UIImage imageNamed:@"unallowed"] forState:UIControlStateNormal];
[_agreeBtn setImage:[UIImage imageNamed:@"allowed"] forState:UIControlStateSelected];
[_agreeBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[_agreeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 11, 0, 0)];
NSString *showText = @"同意《许可协议》《隐私保护指引》";
UIColor *orginColor = [self.dk_manager.themeVersion isEqual:DKThemeVersionNormal] ? MainTextColor : DSWhite;
UIColor *attributeColor = [self.dk_manager.themeVersion isEqual:DKThemeVersionNormal] ? ColorFromHex(0x666666) : ColorFromHex(0x8A8E9B);
NSAttributedString *showAttString = [self getAttributeWith:@[@"《许可协议》",@"《隐私保护指引》"] string:showText orginFont:15 orginColor:orginColor attributeFont:15 attributeColor:attributeColor];
[_agreeBtn setAttributedTitle:showAttString forState:UIControlStateNormal];
[_agreeBtn addTarget:self action:@selector(onButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
WS(weakSelf);
_agreeBtn.titleLabel.tapHighlightedColor = DSClearColor;
[_agreeBtn.titleLabel yb_addAttributeTapActionWithStrings:@[@"同意", @"《许可协议》", @"《隐私保护指引》"] tapClicked:^(UILabel *label, NSString *string, NSRange range, NSInteger index) {
if ([string isEqualToString:@"同意"]) {
weakSelf.agreeBtn.selected = !weakSelf.agreeBtn.selected;
} else {
[weakSelf sendClickMehodWithTag:(index + 3)];
}
}];
}
return _agreeBtn;
}
- (NSAttributedString *)getAttributeWith:(id)sender
string:(NSString *)string
orginFont:(CGFloat)orginFont
orginColor:(UIColor *)orginColor
attributeFont:(CGFloat)attributeFont
attributeColor:(UIColor *)attributeColor
{
__block NSMutableAttributedString *totalStr = [[NSMutableAttributedString alloc] initWithString:string];
[totalStr addAttribute:NSFontAttributeName value:SysFont(orginFont) range:NSMakeRange(0, string.length)];
[totalStr addAttribute:NSForegroundColorAttributeName value:orginColor range:NSMakeRange(0, string.length)];
if ([sender isKindOfClass:[NSArray class]]) {
__block NSString *oringinStr = string;
__weak typeof(self) weakSelf = self;
[sender enumerateObjectsUsingBlock:^(NSString * _Nonnull str, NSUInteger idx, BOOL * _Nonnull stop) {
NSRange range = [oringinStr rangeOfString:str];
[totalStr addAttribute:NSFontAttributeName value:SysFont(attributeFont) range:range];
[totalStr addAttribute:NSForegroundColorAttributeName value:attributeColor range:range];
oringinStr = [oringinStr stringByReplacingCharactersInRange:range withString:[weakSelf getStringWithRange:range]];
}];
} else if ([sender isKindOfClass:[NSString class]]) {
NSRange range = [string rangeOfString:sender];
[totalStr addAttribute:NSFontAttributeName value:SysFont(attributeFont) range:range];
[totalStr addAttribute:NSForegroundColorAttributeName value:attributeColor range:range];
}
return totalStr;
}
- (NSString *)getStringWithRange:(NSRange)range {
NSMutableString *string = [NSMutableString string];
for (int i = 0; i < range.length ; i++) {
[string appendString:@" "];
}
return string;
}
@end
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "allowed.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "allowed@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "allowed@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "bg_login_normal.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "bg_login_normal@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "bg_login_normal@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "bg_login_normal_dk.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "bg_login_normal_dk@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "bg_login_normal_dk@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_apple_login.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_apple_login@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_apple_login@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_apple_login_dk.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_apple_login_dk@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_apple_login_dk@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "unallowed.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "unallowed@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "unallowed@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "wechat.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "wechat@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "wechat@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -16,4 +16,7 @@ NORMAL NIGHT RED ...@@ -16,4 +16,7 @@ NORMAL NIGHT RED
#333333 #FFFFFF #000000 TEXT #333333 #FFFFFF #000000 TEXT
#AAAAAA #FFFFFF #000000 SubTEXT #AAAAAA #FFFFFF #000000 SubTEXT
#FFFFFF #333333 #000000 APPLE_TEXT
//
// UILabel+YBAttributeTextTapAction.h
//
// Created by LYB on 16/7/1.
// Copyright © 2016年 LYB. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol YBAttributeTapActionDelegate <NSObject>
@optional
/**
* YBAttributeTapActionDelegate
*
* @param string 点击的字符串
* @param range 点击的字符串range
* @param index 点击的字符在数组中的index
*/
- (void)yb_tapAttributeInLabel:(UILabel *)label
string:(NSString *)string
range:(NSRange)range
index:(NSInteger)index;
@end
@interface UILabel (YBAttributeTextTapAction)
/**
* 是否打开点击效果,默认是打开
*/
@property (nonatomic, assign) BOOL enabledTapEffect;
/**
* 点击高亮色 默认是[UIColor lightGrayColor] 需打开enabledTapEffect才有效
*/
@property (nonatomic, strong) UIColor * tapHighlightedColor;
/**
* 是否扩大点击范围,默认是打开
*/
@property (nonatomic, assign) BOOL enlargeTapArea;
/**
* 给文本添加点击事件Block回调
*
* @param strings 需要添加的字符串数组
* @param tapClick 点击事件回调
*/
- (void)yb_addAttributeTapActionWithStrings:(NSArray <NSString *> *)strings
tapClicked:(void (^) (UILabel * label, NSString *string, NSRange range, NSInteger index))tapClick;
/**
* 给文本添加点击事件delegate回调
*
* @param strings 需要添加的字符串数组
* @param delegate delegate
*/
- (void)yb_addAttributeTapActionWithStrings:(NSArray <NSString *> *)strings
delegate:(id <YBAttributeTapActionDelegate> )delegate;
/**
* 根据range给文本添加点击事件Block回调
*
* @param ranges 需要添加的Range字符串数组
* @param tapClick 点击事件回调
*/
- (void)yb_addAttributeTapActionWithRanges:(NSArray <NSString *> *)ranges
tapClicked:(void (^) (UILabel * label, NSString *string, NSRange range, NSInteger index))tapClick;
/**
* 根据range给文本添加点击事件delegate回调
*
* @param ranges 需要添加的Range字符串数组
* @param delegate delegate
*/
- (void)yb_addAttributeTapActionWithRanges:(NSArray <NSString *> *)ranges
delegate:(id <YBAttributeTapActionDelegate> )delegate;
/**
* 删除label上的点击事件
*/
- (void)yb_removeAttributeTapActions;
@end
//
// UILabel+YBAttributeTextTapAction.m
//
// Created by LYB on 16/7/1.
// Copyright © 2016年 LYB. All rights reserved.
//
#import "UILabel+YBAttributeTextTapAction.h"
#import <objc/runtime.h>
#import <CoreText/CoreText.h>
#import <Foundation/Foundation.h>
@interface YBAttributeModel : NSObject
@property (nonatomic, copy) NSString *str;
@property (nonatomic) NSRange range;
@end
@implementation YBAttributeModel
@end
@implementation UILabel (YBAttributeTextTapAction)
#pragma mark - AssociatedObjects
- (NSMutableArray *)attributeStrings
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setAttributeStrings:(NSMutableArray *)attributeStrings
{
objc_setAssociatedObject(self, @selector(attributeStrings), attributeStrings, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSMutableDictionary *)effectDic
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setEffectDic:(NSMutableDictionary *)effectDic
{
objc_setAssociatedObject(self, @selector(effectDic), effectDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (BOOL)isTapAction
{
return [objc_getAssociatedObject(self, _cmd) boolValue];
}
- (void)setIsTapAction:(BOOL)isTapAction
{
objc_setAssociatedObject(self, @selector(isTapAction), @(isTapAction), OBJC_ASSOCIATION_ASSIGN);
}
- (void (^)(UILabel *, NSString *, NSRange, NSInteger))tapBlock
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setTapBlock:(void (^)(UILabel *, NSString *, NSRange, NSInteger))tapBlock
{
objc_setAssociatedObject(self, @selector(tapBlock), tapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (id<YBAttributeTapActionDelegate>)delegate
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setDelegate:(id<YBAttributeTapActionDelegate>)delegate
{
objc_setAssociatedObject(self, @selector(delegate), delegate, OBJC_ASSOCIATION_ASSIGN);
}
- (BOOL)enabledTapEffect
{
return [objc_getAssociatedObject(self, _cmd) boolValue];
}
- (void)setEnabledTapEffect:(BOOL)enabledTapEffect
{
objc_setAssociatedObject(self, @selector(enabledTapEffect), @(enabledTapEffect), OBJC_ASSOCIATION_ASSIGN);
self.isTapEffect = enabledTapEffect;
}
- (BOOL)enlargeTapArea
{
NSNumber * number = objc_getAssociatedObject(self, _cmd);
if (!number) {
number = @(YES);
objc_setAssociatedObject(self, _cmd, number, OBJC_ASSOCIATION_ASSIGN);
}
return [number boolValue];
}
- (void)setEnlargeTapArea:(BOOL)enlargeTapArea
{
objc_setAssociatedObject(self, @selector(enlargeTapArea), @(enlargeTapArea), OBJC_ASSOCIATION_ASSIGN);
}
- (UIColor *)tapHighlightedColor
{
UIColor * color = objc_getAssociatedObject(self, _cmd);
if (!color) {
color = [UIColor lightGrayColor];
objc_setAssociatedObject(self, _cmd, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return color;
}
- (void)setTapHighlightedColor:(UIColor *)tapHighlightedColor
{
objc_setAssociatedObject(self, @selector(tapHighlightedColor), tapHighlightedColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (BOOL)isTapEffect
{
return [objc_getAssociatedObject(self, _cmd) boolValue];
}
- (void)setIsTapEffect:(BOOL)isTapEffect
{
objc_setAssociatedObject(self, @selector(isTapEffect), @(isTapEffect), OBJC_ASSOCIATION_ASSIGN);
}
#pragma mark - mainFunction
- (void)yb_addAttributeTapActionWithStrings:(NSArray <NSString *> *)strings tapClicked:(void (^) (UILabel * label, NSString *string, NSRange range, NSInteger index))tapClick
{
[self yb_removeAttributeTapActions];
[self yb_getRangesWithStrings:strings];
self.userInteractionEnabled = YES;
if (self.tapBlock != tapClick) {
self.tapBlock = tapClick;
}
}
- (void)yb_addAttributeTapActionWithStrings:(NSArray <NSString *> *)strings
delegate:(id <YBAttributeTapActionDelegate> )delegate
{
[self yb_removeAttributeTapActions];
[self yb_getRangesWithStrings:strings];
self.userInteractionEnabled = YES;
if (self.delegate != delegate) {
self.delegate = delegate;
}
}
- (void)yb_addAttributeTapActionWithRanges:(NSArray<NSString *> *)ranges tapClicked:(void (^)(UILabel *, NSString *, NSRange, NSInteger))tapClick
{
[self yb_removeAttributeTapActions];
[self yb_getRangesWithRanges:ranges];
self.userInteractionEnabled = YES;
if (self.tapBlock != tapClick) {
self.tapBlock = tapClick;
}
}
- (void)yb_addAttributeTapActionWithRanges:(NSArray<NSString *> *)ranges delegate:(id<YBAttributeTapActionDelegate>)delegate
{
[self yb_removeAttributeTapActions];
[self yb_getRangesWithRanges:ranges];
self.userInteractionEnabled = YES;
if (self.delegate != delegate) {
self.delegate = delegate;
}
}
- (void)yb_removeAttributeTapActions
{
self.tapBlock = nil;
self.delegate = nil;
self.effectDic = nil;
self.isTapAction = NO;
self.attributeStrings = [NSMutableArray array];
}
#pragma mark - touchAction
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isTapAction) {
[super touchesBegan:touches withEvent:event];
return;
}
if (objc_getAssociatedObject(self, @selector(enabledTapEffect))) {
self.isTapEffect = self.enabledTapEffect;
}
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
__weak typeof(self) weakSelf = self;
BOOL ret = [self yb_getTapFrameWithTouchPoint:point result:^(NSString *string, NSRange range, NSInteger index) {
if (weakSelf.isTapEffect) {
[weakSelf yb_saveEffectDicWithRange:range];
[weakSelf yb_tapEffectWithStatus:YES];
}
}];
if (!ret) {
[super touchesBegan:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isTapAction) {
[super touchesEnded:touches withEvent:event];
return;
}
if (self.isTapEffect) {
[self performSelectorOnMainThread:@selector(yb_tapEffectWithStatus:) withObject:nil waitUntilDone:NO];
}
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
__weak typeof(self) weakSelf = self;
BOOL ret = [self yb_getTapFrameWithTouchPoint:point result:^(NSString *string, NSRange range, NSInteger index) {
if (weakSelf.tapBlock) {
weakSelf.tapBlock (weakSelf, string, range, index);
}
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(yb_tapAttributeInLabel:string:range:index:)]) {
[weakSelf.delegate yb_tapAttributeInLabel:weakSelf string:string range:range index:index];
}
}];
if (!ret) {
[super touchesEnded:touches withEvent:event];
}
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isTapAction) {
[super touchesCancelled:touches withEvent:event];
return;
}
if (self.isTapEffect) {
[self performSelectorOnMainThread:@selector(yb_tapEffectWithStatus:) withObject:nil waitUntilDone:NO];
}
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
__weak typeof(self) weakSelf = self;
BOOL ret = [self yb_getTapFrameWithTouchPoint:point result:^(NSString *string, NSRange range, NSInteger index) {
if (weakSelf.tapBlock) {
weakSelf.tapBlock (weakSelf, string, range, index);
}
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(yb_tapAttributeInLabel:string:range:index:)]) {
[weakSelf.delegate yb_tapAttributeInLabel:weakSelf string:string range:range index:index];
}
}];
if (!ret) {
[super touchesCancelled:touches withEvent:event];
}
}
#pragma mark - getTapFrame
- (BOOL)yb_getTapFrameWithTouchPoint:(CGPoint)point result:(void (^) (NSString *string , NSRange range , NSInteger index))resultBlock
{
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self.attributedText);
CGMutablePathRef Path = CGPathCreateMutable();
CGPathAddRect(Path, NULL, CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height + 20));
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), Path, NULL);
CFArrayRef lines = CTFrameGetLines(frame);
CGFloat total_height = [self yb_textSizeWithAttributedString:self.attributedText width:self.bounds.size.width numberOfLines:0].height;
if (!lines) {
CFRelease(frame);
CFRelease(framesetter);
CGPathRelease(Path);
return NO;
}
CFIndex count = CFArrayGetCount(lines);
CGPoint origins[count];
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), origins);
CGAffineTransform transform = [self yb_transformForCoreText];
for (CFIndex i = 0; i < count; i++) {
CGPoint linePoint = origins[i];
CTLineRef line = CFArrayGetValueAtIndex(lines, i);
CGRect flippedRect = [self yb_getLineBounds:line point:linePoint];
CGRect rect = CGRectApplyAffineTransform(flippedRect, transform);
CGFloat lineOutSpace = (self.bounds.size.height - total_height) / 2;
rect.origin.y = lineOutSpace + [self yb_getLineOrign:line];
if (self.enlargeTapArea) {
rect.origin.y -= 5;
rect.size.height += 10;
}
if (CGRectContainsPoint(rect, point)) {
CGPoint relativePoint = CGPointMake(point.x - CGRectGetMinX(rect), point.y - CGRectGetMinY(rect));
CFIndex index = CTLineGetStringIndexForPosition(line, relativePoint);
CGFloat offset;
CTLineGetOffsetForStringIndex(line, index, &offset);
if (offset > relativePoint.x) {
index = index - 1;
}
NSInteger link_count = self.attributeStrings.count;
for (int j = 0; j < link_count; j++) {
YBAttributeModel *model = self.attributeStrings[j];
NSRange link_range = model.range;
if (NSLocationInRange(index, link_range)) {
if (resultBlock) {
resultBlock (model.str , model.range , (NSInteger)j);
}
CFRelease(frame);
CFRelease(framesetter);
CGPathRelease(Path);
return YES;
}
}
}
}
CFRelease(frame);
CFRelease(framesetter);
CGPathRelease(Path);
return NO;
}
- (CGAffineTransform)yb_transformForCoreText
{
return CGAffineTransformScale(CGAffineTransformMakeTranslation(0, self.bounds.size.height), 1.f, -1.f);
}
- (CGRect)yb_getLineBounds:(CTLineRef)line point:(CGPoint)point
{
CGFloat ascent = 0.0f;
CGFloat descent = 0.0f;
CGFloat leading = 0.0f;
CGFloat width = (CGFloat)CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
CGFloat height = 0.0f;
CFRange range = CTLineGetStringRange(line);
NSAttributedString * attributedString = [self.attributedText attributedSubstringFromRange:NSMakeRange(range.location, range.length)];
if ([attributedString.string hasSuffix:@"\n"] && attributedString.string.length > 1) {
attributedString = [attributedString attributedSubstringFromRange:NSMakeRange(0, attributedString.length - 1)];
}
height = [self yb_textSizeWithAttributedString:attributedString width:self.bounds.size.width numberOfLines:0].height;
return CGRectMake(point.x, point.y , width, height);
}
- (CGFloat)yb_getLineOrign:(CTLineRef)line
{
CFRange range = CTLineGetStringRange(line);
if (range.location == 0) {
return 0.;
}else {
NSAttributedString * attributedString = [self.attributedText attributedSubstringFromRange:NSMakeRange(0, range.location)];
if ([attributedString.string hasSuffix:@"\n"] && attributedString.string.length > 1) {
attributedString = [attributedString attributedSubstringFromRange:NSMakeRange(0, attributedString.length - 1)];
}
return [self yb_textSizeWithAttributedString:attributedString width:self.bounds.size.width numberOfLines:0].height;
}
}
- (CGSize)yb_textSizeWithAttributedString:(NSAttributedString *)attributedString width:(float)width numberOfLines:(NSInteger)numberOfLines
{
@autoreleasepool {
UILabel *sizeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
sizeLabel.numberOfLines = numberOfLines;
sizeLabel.attributedText = attributedString;
CGSize fitSize = [sizeLabel sizeThatFits:CGSizeMake(width, MAXFLOAT)];
return fitSize;
}
}
#pragma mark - tapEffect
- (void)yb_tapEffectWithStatus:(BOOL)status
{
if (self.isTapEffect) {
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText];
NSMutableAttributedString *subAtt = [[NSMutableAttributedString alloc] initWithAttributedString:[[self.effectDic allValues] firstObject]];
NSRange range = NSRangeFromString([[self.effectDic allKeys] firstObject]);
if (status) {
[subAtt addAttribute:NSBackgroundColorAttributeName value:self.tapHighlightedColor range:NSMakeRange(0, subAtt.string.length)];
[attStr replaceCharactersInRange:range withAttributedString:subAtt];
}else {
[attStr replaceCharactersInRange:range withAttributedString:subAtt];
}
self.attributedText = attStr;
}
}
- (void)yb_saveEffectDicWithRange:(NSRange)range
{
self.effectDic = [NSMutableDictionary dictionary];
NSAttributedString *subAttribute = [self.attributedText attributedSubstringFromRange:range];
[self.effectDic setObject:subAttribute forKey:NSStringFromRange(range)];
}
#pragma mark - getRange
- (void)yb_getRangesWithStrings:(NSArray <NSString *> *)strings
{
if (self.attributedText == nil) {
self.isTapAction = NO;
return;
}
self.isTapAction = YES;
self.isTapEffect = YES;
__block NSString *totalStr = self.attributedText.string;
self.attributeStrings = [NSMutableArray array];
__weak typeof(self) weakSelf = self;
[strings enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSRange range = [totalStr rangeOfString:obj];
if (range.length != 0) {
totalStr = [totalStr stringByReplacingCharactersInRange:range withString:[weakSelf yb_getStringWithRange:range]];
YBAttributeModel *model = [YBAttributeModel new];
model.range = range;
model.str = obj;
[weakSelf.attributeStrings addObject:model];
}
}];
}
- (void)yb_getRangesWithRanges:(NSArray <NSString *> *)ranges
{
if (self.attributedText == nil) {
self.isTapAction = NO;
return;
}
self.isTapAction = YES;
self.isTapEffect = YES;
__block NSString *totalStr = self.attributedText.string;
self.attributeStrings = [NSMutableArray array];
__weak typeof(self) weakSelf = self;
[ranges enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSRange range = NSRangeFromString(obj);
NSAssert(totalStr.length >= range.location + range.length, @"NSRange(%ld,%ld) is out of bounds",range.location,range.length);
NSString * string = [totalStr substringWithRange:range];
YBAttributeModel *model = [YBAttributeModel new];
model.range = range;
model.str = string;
[weakSelf.attributeStrings addObject:model];
}];
}
- (NSString *)yb_getStringWithRange:(NSRange)range
{
NSMutableString *string = [NSMutableString string];
for (int i = 0; i < range.length ; i++) {
[string appendString:@" "];
}
return string;
}
#pragma mark - KVO
- (void)yb_addObserver
{
[self addObserver:self forKeyPath:@"attributedText" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];
}
- (void)yb_removeObserver
{
id info = self.observationInfo;
NSString * key = @"attributedText";
NSArray *array = [info valueForKey:@"_observances"];
for (id objc in array) {
id Properties = [objc valueForKeyPath:@"_property"];
NSString *keyPath = [Properties valueForKeyPath:@"_keyPath"];
if ([key isEqualToString:keyPath]) {
[self removeObserver:self forKeyPath:@"attributedText" context:nil];
}
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"attributedText"]) {
if (self.isTapAction) {
if (![change[NSKeyValueChangeNewKey] isEqual: change[NSKeyValueChangeOldKey]]) {
}
}
}
}
@end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!