Files
peko-ios/YuMi/Modules/YMLogin/View/CustomView/UserPrivacyView.m
2023-10-28 04:46:10 +08:00

212 lines
7.6 KiB
Objective-C

//
// UserPrivacyView.m
// YUMI
//
// Created by YUMI on 2021/11/1.
//
#import "UserPrivacyView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "YUMIConstant.h"
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
#import "YUMIHtmlUrl.h"
#import "TTPopup.h"
#import "UIImage+Utils.h"
///VC
#import "XPWebViewController.h"
NSString * const kYouMiNumberCountKey = @"kYouMinumbernnagna";
@interface UserPrivacyView ()
///title
@property (nonatomic, strong) UILabel *titleLabel;
///内容
@property (nonatomic, strong) YYTextView *contentLabel;
///容器
@property (nonatomic,strong) UIStackView *stackView;
///确认
@property (nonatomic, strong) UIButton *confirmButton;
///退出
@property (nonatomic, strong) UIButton *exitButton;
@end
@implementation UserPrivacyView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Response
- (void)onAgreementButtonClick:(UIButton *)sender {
if (sender == self.confirmButton) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"isShow" forKey:kYouMiNumberCountKey];
[defaults synchronize];
[TTPopup dismiss];
}
}
- (void)exitButtonClick:(UIButton *)sender {
[self exitApplication];
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor whiteColor];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 10;
[self addSubview:self.titleLabel];
[self addSubview:self.contentLabel];
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.exitButton];
[self.stackView addArrangedSubview:self.confirmButton];
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(KScreenWidth - 38 * 2);
make.height.mas_equalTo(424);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(18);
make.centerX.mas_equalTo(self);
}];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(55);
make.left.mas_equalTo(28);
make.right.mas_equalTo(-28);
make.bottom.mas_equalTo(-68);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-20);
make.left.right.mas_equalTo(self).inset(15);
make.height.mas_equalTo(36);
}];
}
///退出app
- (void)exitApplication {
[TTPopup dismiss];
[UIView beginAnimations:@"exitApplication" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self cache:NO];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
[UIView commitAnimations];
}
- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID compare:@"exitApplication"] == 0) {
exit(0);
}
}
#pragma mark - getters and setters
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:16.f weight:UIFontWeightMedium];
_titleLabel.textColor = [DJDKMIMOMColor alertTitleColor];
_titleLabel.text = [NSString stringWithFormat:YMLocalizedString(@"UserPrivacyView0"), AppName];
}
return _titleLabel;
}
- (YYTextView *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[YYTextView alloc]init];
_contentLabel.editable = NO;
_contentLabel.showsVerticalScrollIndicator = NO;
_contentLabel.showsHorizontalScrollIndicator = NO;
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineSpacing = 4;
NSString * agreement = [NSString stringWithFormat:YMLocalizedString(@"UserPrivacyView1"), AppName];
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] init];
NSAttributedString *att1 = [[NSAttributedString alloc] initWithString:agreement attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14], NSForegroundColorAttributeName : [DJDKMIMOMColor textThirdColor], NSParagraphStyleAttributeName : paragraphStyle, NSKernAttributeName : @(1.0)}];
NSMutableAttributedString *att2 = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"UserPrivacyView2") attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14 weight:UIFontWeightMedium], NSForegroundColorAttributeName : [DJDKMIMOMColor textThirdColor], NSParagraphStyleAttributeName : paragraphStyle, NSKernAttributeName : @(1.0)}];
@kWeakify(self);
[att2 yy_setTextHighlightRange:NSMakeRange(8, 6) color:[DJDKMIMOMColor appMainColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
[TTPopup dismiss];
XPWebViewController *web = [[XPWebViewController alloc] init];
web.url = URLWithType(kPrivacyURL);
[self.controller.navigationController pushViewController:web animated:YES];
}];
[att2 yy_setTextHighlightRange:NSMakeRange(15, 6) color:[DJDKMIMOMColor appMainColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
[TTPopup dismiss];
XPWebViewController *web = [[XPWebViewController alloc] init];
web.url = URLWithType(kUserProtocalURL);
[self.controller.navigationController pushViewController:web animated:YES];
}];
[attStr appendAttributedString:att1];
[attStr appendAttributedString:att2];
_contentLabel.attributedText = attStr;
}
return _contentLabel;
}
- (UIButton *)confirmButton {
if (!_confirmButton) {
_confirmButton = [[UIButton alloc]init];
[_confirmButton setTitle:YMLocalizedString(@"UserPrivacyView3") forState:UIControlStateNormal];
_confirmButton.titleLabel.font = [UIFont systemFontOfSize:15];
[_confirmButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
[_confirmButton setBackgroundImage:image forState:UIControlStateNormal];
_confirmButton.layer.cornerRadius = 18;
_confirmButton.layer.masksToBounds = YES;
[_confirmButton addTarget:self action:@selector(onAgreementButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmButton;
}
- (UIButton *)exitButton {
if (!_exitButton) {
_exitButton = [[UIButton alloc]init];
[_exitButton setTitle:YMLocalizedString(@"UserPrivacyView4") forState:UIControlStateNormal];
_exitButton.titleLabel.font = [UIFont systemFontOfSize:15];
[_exitButton setTitleColor:[DJDKMIMOMColor cancelButtonTextColor] forState:UIControlStateNormal];
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor cancelButtonGradientStartColor],[DJDKMIMOMColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
[_exitButton setBackgroundImage:image forState:UIControlStateNormal];
_exitButton.layer.cornerRadius = 18;
_exitButton.layer.masksToBounds = YES;
[_exitButton addTarget:self action:@selector(exitButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _exitButton;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFillEqually;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 20;
}
return _stackView;
}
@end