携手创作,共同生长!这是我参与「日新方案 8 月更文应战」的第27天,点击查看活动详情
引言
本文针对不熟悉iOS代码的读者,如果是有经验的开发请看这篇文章:kunnan.blog.csdn.net/article/det…
准备常识:采用富文本属性attributedText进行内容设置blog.csdn.net/z929118967/…
本地化相关文章:blog.csdn.net/z929118967/…
适配相关文章:iOS15 UI适配之导航条主题: 背景色彩、标题色彩 https://kunnan.blog.csdn.net/article/details/121090938
I demo项目简介
1.1 使用Cocoapods
管理第三方库依靠
在项目目录下touch Podfile
之后声明依靠库,然后答应pod intsall
进行依靠的装置
iOS小技能:第三方库管理规范 https://blog.csdn.net/z929118967/article/details/119206808
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
inhibit_all_warnings!
target 'AgreementView' do
pod 'Masonry'
pod 'ReactiveObjC'
pod 'AXWebViewController'
end
1.2 使用MVVM架构
使用ReactiveObjC
简单的完成MVVM,在 iOS 的 MVVM 完成中,使用 RAC
来在 view
和 viewModel
之间充任 binder
的人物,优雅地完成两者之间的信息同步。此外,我们还可以把 RAC 用在 model 层,使用Signal
来代表异步的数据获取操作,比如读取文件、访问数据库和网络请求等(同样可以在 MVC 的 model 层这么用)。
———————————————— 版权声明:本文为CSDN博主「iOS逆向」的原创文章,遵从CC 4.0 BY-SA版权协议,转载请>附上原文出处链接及本声明。 原文链接:blog.csdn.net/z929118967/…
1.3 使用常量装备数据
装备常量:QCTConsts.h
/**
装备隐私政策链接URL
*/
extern NSString * _Nonnull const k_serviceAgreement_URL;
/**
装备隐私政策链接URL
*/
NSString * const k_serviceAgreement_URL = @"https://kunnan.blog.csdn.net";
装备本地化字符串:Localizable.strings
#define QCTLocal(key, ...) NSLocalizedString(key, nil)
"agree" = "赞同";
"disagree" = "不赞同";
1.4 赞同/回绝协议处理逻辑
会话目标新增一个属性,用于判断登录界面是否显现隐私弹框
/**
是否弹出协议框:
没有赞同时,在登录界面就需要一向展现弹框,只要点击赞同才能消失弹框。
回绝是停留在当时界面,或者退出app
*/
@property (nonatomic,assign) BOOL isShowPrivacyButNoAgree;
- 赞同协议
[_serviceAgreementView.confirmSubject subscribeNext:^(id _Nullable x) {
@strongify(self);
[self.modal hide:YES];
NSLog(@"赞同协议,开端保存登录信息,进入主页");
// [self.viewModel.gotojumpHomeRACSubject sendNext:@1];// 读者自己完成
}];
- 不赞同协议处理逻辑
[_serviceAgreementView.cancelSubject subscribeNext:^(id _Nullable x) {
NSLog(@"处理方式1. 不赞同协议,给温馨提示,点击我知道了,停留在当时界面。(进入死循环)");
// exit(0);
NSLog(@"处理方式2. 不赞同协议,给温馨提示,点击我知道了,停留在当时界面。(进入死循环)");
[[[UIAlertView alloc]initWithTitle:QCTLocal(@"QCT_qct_Tips") message:QCTLocal(@"QCT_We_only") delegate:nil cancelButtonTitle:QCTLocal(@"QCT_Got_it") otherButtonTitles:nil, nil] show];
}];
1.5 demo下载
重视工号:iOS逆向,加我,发个奶茶红包表诚心即可获取
经不可以轻传,也不可以轻取。
想要免费意见主张的行为都是耍流氓”,他不是在请教,即使有用,也不会对你感谢,他不准备支付任何价值,哪怕是一句谢谢。
全部寻求免费主张的行为都是耍流氓;愿意花钱的提问者才是真心的。
II WebVC导航栏主题的适配(iOS15)
iOS15 UI适配之导航条主题: 背景色彩、标题色彩 https://kunnan.blog.csdn.net/article/details/121090938
#pragma mark - ******** 设置列表控制器的款式
+ (void)setupListnavigationItemAndBarStyle:(UIViewController*)vc{
// 修正回来箭头款式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
[vc.navigationController.navigationBar setTintColor: kNavListbackArrowColor];
[vc.navigationController.navigationBar setBackgroundImage:[self createImageWithColor: [UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
[self setupBackgroundImage4ios15:vc];
}
/**
导航栏主题的适配(iOS15)
*/
+(void)setupBackgroundImage4ios15:(UIViewController*)vc{
// 设置标题色彩
NSDictionary *dict = @{NSForegroundColorAttributeName: kNavListTextColor,NSFontAttributeName:kNavListNSFontAttributeName};
[vc.navigationController.navigationBar setTitleTextAttributes:dict];
NSDictionary *dictitem = @{NSForegroundColorAttributeName: kNavListbackArrowColor,NSFontAttributeName:kNavListUIBarButtonItemNSFontAttributeName};
for (UIBarButtonItem* item in vc.navigationItem.leftBarButtonItems) {
[item setTitleTextAttributes:dictitem forState:UIControlStateNormal];
// [item setTitleTextAttributes:dict];
}
if(@available(iOS 15.0, *)) {
UINavigationBar *navigationBar = vc.navigationController.navigationBar;
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
appearance.titleTextAttributes =dict;
appearance.backgroundImage = [self createImageWithColor: [UIColor whiteColor]];
appearance.backgroundColor = UIColor.whiteColor;
appearance.shadowColor= UIColor.clearColor;
[UIBarButtonItem.appearance setTitleTextAttributes:dictitem forState:UIControlStateNormal];
UIBarButtonItem.appearance.tintColor =kNavListbackArrowColor;
navigationBar.standardAppearance = appearance;
navigationBar.scrollEdgeAppearance = appearance;
}else{
[vc.navigationController.navigationBar setBackgroundImage:[self createImageWithColor: [UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
}
}
+ (UIImage *) createImageWithColor: (UIColor *) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
see also
给付费用户的一封来信:blog.csdn.net/z929118967/…