Commit 279e23dd authored by Mazy's avatar Mazy

Merge remote-tracking branch 'refs/remotes/origin/master'

Conflicts:
	GYDemo/GYDemo.xcodeproj/project.pbxproj
parents 593e5b0a d8f64bb6
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
self.cancelButton.userInteractionEnabled = true; self.cancelButton.userInteractionEnabled = true;
} }
}]; }];
self.gainAmountRightLabel.text = [Data getAcquisitionUnit];
} }
- (void)layoutSubviews { - (void)layoutSubviews {
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
<color key="textColor" red="0.91764705879999997" green="0.31764705879999999" blue="0.2901960784" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.91764705879999997" green="0.31764705879999999" blue="0.2901960784" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TGu-2Q-UAs"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TGu-2Q-UAs">
<rect key="frame" x="219.33333333333331" y="0.0" width="21.666666666666657" height="36"/> <rect key="frame" x="219.33333333333331" y="0.0" width="21.666666666666657" height="36"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/> <fontDescription key="fontDescription" type="system" pointSize="21"/>
<color key="textColor" red="0.56470588239999997" green="0.36078431370000003" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.56470588239999997" green="0.36078431370000003" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
- (void)setAwardNum:(NSString *)awardNum{ - (void)setAwardNum:(NSString *)awardNum{
_awardNum = awardNum; _awardNum = awardNum;
NSString * amt = [NSString stringWithFormat:@"%.2f", [awardNum integerValue]*1.0/100]; NSString * amt = [NSString stringWithFormat:@"%.2f", [awardNum integerValue]*1.0/100];
NSString * amtStr = [NSString stringWithFormat:@"%@元", amt]; NSString * amtStr = [NSString stringWithFormat:@"%@%@", amt,[Data getAcquisitionUnit]];
NSMutableAttributedString * att = [[NSMutableAttributedString alloc] initWithString:amtStr]; NSMutableAttributedString * att = [[NSMutableAttributedString alloc] initWithString:amtStr];
[att addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:58]} range:[amtStr rangeOfString:amt]]; [att addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:58]} range:[amtStr rangeOfString:amt]];
[att addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:32]} range:[amtStr rangeOfString:@"元"]]; [att addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:32]} range:[amtStr rangeOfString:@"元"]];
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#import "GYSettingViewController.h" #import "GYSettingViewController.h"
#import "GYLoginViewController.h" #import "GYLoginViewController.h"
#import "GYCashSixAwardAlertView.h" #import "GYCashSixAwardAlertView.h"
#import "WelfareCenterVC.h"
UnityFramework* UnityFrameworkLoad() UnityFramework* UnityFrameworkLoad()
{ {
...@@ -127,16 +128,28 @@ NSDictionary* appLaunchOpts; ...@@ -127,16 +128,28 @@ NSDictionary* appLaunchOpts;
// 跳转每日福利 // 跳转每日福利
- (void)ios_oneveryDayWelfareClick { - (void)ios_oneveryDayWelfareClick {
[[CGUserManager shared] addLocCollection:@"show_welfare_center_page" value:@""]; [[CGUserManager shared] addLocCollection:@"show_welfare_center_page" value:@""];
[self unityVideo:false];
GYWebViewController * web = [[GYWebViewController alloc] init]; GYWebViewController * web = [[GYWebViewController alloc] init];
web.url = [[CGUserManager shared].h5_url objectForKey:@"welfareurl"]; web.url = [[CGUserManager shared].h5_url objectForKey:@"welfareurl"];
// WelfareCenterVC * vc = [[WelfareCenterVC alloc]init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:web]; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:web];
nav.modalPresentationStyle = UIModalPresentationFullScreen; nav.modalPresentationStyle = UIModalPresentationFullScreen;
[[[self ufw] appController].window.rootViewController presentViewController:nav animated:YES completion:nil];
[[[self ufw] appController].window.rootViewController presentViewController:nav
animated:YES
completion:nil];
WEAKSELF
[self unityVideo:false]; //关闭背景音乐
web.dismissCallBack = ^{ web.dismissCallBack = ^{
[self unityVideo:true]; [weakSelf unityVideo:true]; //关闭背景音乐
}; };
} }
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "BottomOfTheBackground@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "BottomOfTheBackground@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "CollectedGrey@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "CollectedGrey@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "DottedLine@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "DottedLine@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "FinishedDiamonds@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "FinishedDiamonds@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "GetItNow@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "GetItNow@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "MissionDiamond@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "MissionDiamond@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ToFinishRed@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ToFinishRed@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "UnfinishedDiamond@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "UnfinishedDiamond@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -17,4 +17,7 @@ ...@@ -17,4 +17,7 @@
- (void)InitPlist; - (void)InitPlist;
- (void)removeDicForKey:(id)key; - (void)removeDicForKey:(id)key;
//获取单位
+(NSString *)getAcquisitionUnit;
@end @end
...@@ -85,5 +85,14 @@ if(![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) ...@@ -85,5 +85,14 @@ if(![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
[DataDic writeToFile:plistPath atomically:YES]; [DataDic writeToFile:plistPath atomically:YES];
} }
} }
//获取单位
+(NSString *)getAcquisitionUnit;{
NSString *status = [[CGUserManager shared].appSwitch[@"isopenH5"] stringValue];
if ([status isEqualToString: @"0"]) {
return @"钻";
}else{
return @"元";
}
return @"钻";
}
@end @end
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
//测试 //测试
#define ServerReport @"http://reporttest.zhangxinhulian.com" //#define ServerReport @"http://reporttest.zhangxinhulian.com"
#define ServerHost @"https://feedapitest.zhangxinhulian.com" // 服务端接口地址 //#define ServerHost @"https://feedapitest.zhangxinhulian.com" // 服务端接口地址
#define ServerAds @"http://bstest.zhangxinhulian.com/v4/ads" //#define ServerAds @"http://bstest.zhangxinhulian.com/v4/ads"
//正式 //正式
//#define ServerReport @"http://report.clouddistribute.net" #define ServerReport @"http://report.clouddistribute.net"
//#define ServerHost @"https://feedapi.clouddistribute.net" // 服务端接口地址 #define ServerHost @"https://feedapi.clouddistribute.net" // 服务端接口地址
//#define ServerAds @"http://bs.clouddistribute.net/v4/ads" #define ServerAds @"http://bs.clouddistribute.net/v4/ads"
#define WXAppId @"wxe7a03eb52cce1b51" #define WXAppId @"wxe7a03eb52cce1b51"
#define WXAppSecret @"6fa72a89ea188c4dff5729cff328b587" #define WXAppSecret @"6fa72a89ea188c4dff5729cff328b587"
......
...@@ -42,6 +42,11 @@ typedef enum : NSUInteger { ...@@ -42,6 +42,11 @@ typedef enum : NSUInteger {
is_bind_wx, //是否绑定 is_bind_wx, //是否绑定
getRedPackList, // 配置列表 getRedPackList, // 配置列表
cloudCheck, //云朵加速校验 cloudCheck, //云朵加速校验
task_process,// 获取福利中心进度
taskListWithStat,//获取福利中心列表和状态
//
} TQNetwortGetAction; } TQNetwortGetAction;
......
...@@ -88,6 +88,11 @@ static CGNetworkTools* _tools = nil; ...@@ -88,6 +88,11 @@ static CGNetworkTools* _tools = nil;
return @"/app/v1/game/farm/rp_list"; return @"/app/v1/game/farm/rp_list";
case cloudCheck: case cloudCheck:
return @"/app/v1/game/farm/cloud_check"; return @"/app/v1/game/farm/cloud_check";
case task_process:
return @"/app/v2/novel/taskListWithStat";
case taskListWithStat:
return @"/app/v1/game/task_process";
default: default:
return @""; return @"";
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
@implementation GYWebViewController @implementation GYWebViewController
- (void)viewWillAppear:(BOOL)animated{ - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; [super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:!_showNav animated:true]; [self.navigationController setNavigationBarHidden:!_showNav animated:true];
...@@ -103,6 +105,8 @@ ...@@ -103,6 +105,8 @@
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
_requestW = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]]; _requestW = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]];
//清除请求
[self.webView loadRequest:_requestW]; [self.webView loadRequest:_requestW];
if (!_showNav){ if (!_showNav){
...@@ -463,6 +467,8 @@ ...@@ -463,6 +467,8 @@
[_webView removeObserver:self forKeyPath:@"estimatedProgress"]; [_webView removeObserver:self forKeyPath:@"estimatedProgress"];
[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"backTrack"]; [_webView.configuration.userContentController removeScriptMessageHandlerForName:@"backTrack"];
[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"settingCallBack"]; [_webView.configuration.userContentController removeScriptMessageHandlerForName:@"settingCallBack"];
// [[NSURLCache sharedURLCache] removeCachedResponseForRequest:self.requestW];
} }
/// 刷新webView /// 刷新webView
......
...@@ -115,32 +115,22 @@ ...@@ -115,32 +115,22 @@
- (void)loadData{ - (void)loadData{
WEAKSELF; WEAKSELF;
[MBProgressHUD showLoading:@"loading"]; [MBProgressHUD showLoading:@"loading"];
//请求进度
// [self.dataSource requestMusicListWithPreferenceData:self.preferenceID results:^(NSArray * _Nonnull array) { [[CGNetworkTools shared] getWithAction:task_process parameters:@{} success:^(id _Nonnull response) {
// if (array.count == 0) {
// return;
// } } failure:^(NSError * _Nonnull error) {
//
// }];
// [MBProgressHUD hideHUD];
// [weakSelf.tableView.mj_footer endRefreshing]; // 请求列表
// if (array.count < 20) { [[CGNetworkTools shared] getWithAction:taskListWithStat parameters:@{} success:^(id _Nonnull response) {
// [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
// }else{ } failure:^(NSError * _Nonnull error) {
//
// } }];
// if (self.dataSource.currentPage == 1) {
// [weakSelf.dataArray removeAllObjects];
// }
// [weakSelf.dataArray addObjectsFromArray:array];
//
// [weakSelf.tableView reloadData];
//
// }];
} }
......
//
// UIColor+HExtension.h
// ExerciseAnimation
//
// Created by L.mac on 2019/5/10.
// Copyright © 2019 L.mac. All rights reserved.
//
#import <UIKit/UIKit.h>
// MARK: - 颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define kColorWithRGB(r, g, b) [UIColor colorWithRed:(r) / 255.f green:(g) / 255.f blue:(b) / 255.f alpha:1.f]
#define kColorFromHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
NS_ASSUME_NONNULL_BEGIN
@interface UIColor (HExtension)
/**
使用 16 进制数字创建颜色,例如 0xFF0000 创建红色
@param hex 16 进制无符号32位整数
@return 颜色
*/
+ (instancetype)colorWithHex:(uint32_t)hex;
/**
产生随机色
@return 随机色
*/
+ (instancetype)randomColor;
/**
支持三种格式颜色字符串@"123456" @"0x123456" @"#123456"输入
@param color 十六进制颜色字符串
@param alpha 透明度
@return Color
*/
+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha;
/**
支持三种格式颜色字符串@"123456" @"0x123456" @"#123456"输入
@param color 十六进制颜色字符串
@return Color
*/
+ (UIColor *)colorWithHexString:(NSString *)color;
@end
NS_ASSUME_NONNULL_END
//
// UIColor+HExtension.m
// ExerciseAnimation
//
// Created by L.mac on 2019/5/10.
// Copyright © 2019 L.mac. All rights reserved.
//
#import "UIColor+HExtension.h"
@implementation UIColor (HExtension)
+ (instancetype)colorWithHex:(uint32_t)hex {
int red, green, blue;
blue = hex & 0x000000FF;
green = ((hex & 0x0000FF00) >> 8);
red = ((hex & 0x00FF0000) >> 16);
return [UIColor colorWithRed:red/255.0f
green:green/255.0f
blue:blue/255.0f
alpha:1.0f];
}
+ (instancetype)randomColor {
return [UIColor colorWithRed:((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0];
}
+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha{
NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
// String should be 6 or 8 characters
if ([cString length] < 6)
{
return [UIColor clearColor];
}
// strip 0X if it appears
//如果是0x开头的,那么截取字符串,字符串从索引为2的位置开始,一直到末尾
if ([cString hasPrefix:@"0X"])
{
cString = [cString substringFromIndex:2];
}
//如果是#开头的,那么截取字符串,字符串从索引为1的位置开始,一直到末尾
if ([cString hasPrefix:@"#"])
{
cString = [cString substringFromIndex:1];
}
if ([cString length] != 6)
{
return [UIColor clearColor];
}
// Separate into r, g, b substrings
NSRange range;
range.location = 0;
range.length = 2;
//r
NSString *rString = [cString substringWithRange:range];
//g
range.location = 2;
NSString *gString = [cString substringWithRange:range];
//b
range.location = 4;
NSString *bString = [cString substringWithRange:range];
// Scan values
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha];
}
+ (UIColor *)colorWithHexString:(NSString *)color{
//默认alpha值为1
return [self colorWithHexString:color alpha:1.0f];
}
@end
//
// UIView+DHExtension.h
// DHZL
//
// Created by Genius Cleaner on 2020/6/24.
// Copyright © 2020 Genius Cleaner. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (DHExtension)
- (void)addEmptyDataSet: (CGFloat)offset image: (UIImage *)image title: (NSString *)title;
-(void)removeEmptyDataSet: (BOOL)animated;
-(void)roundCorners: (UIRectCorner)corners radius: (CGFloat)radius;
- (void)roundCorners: (UIRectCorner)corners radius: (CGFloat)radius bounds:(CGRect)bounds;
-(void)roundCornersAllRadius:(CGFloat)radius;
@end
NS_ASSUME_NONNULL_END
//
// UIView+DHExtension.m
// DHZL
//
// Created by Genius Cleaner on 2020/6/24.
// Copyright © 2020 Genius Cleaner. All rights reserved.
//
#import "UIView+DHExtension.h"
#import "UIColor+HExtension.h"
@implementation UIView (DHExtension)
- (void)addEmptyDataSet: (CGFloat)offset image: (UIImage *)image title: (NSString *)title {
UIView *tagView = [self viewWithTag:1280];
if (tagView) {
[tagView removeFromSuperview];
}
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
contentView.backgroundColor = [UIColor whiteColor];
contentView.tag = 1280;
[self addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
UIImageView *iconView = [[UIImageView alloc] initWithImage: image];
iconView.contentMode = UIViewContentModeCenter;
[contentView addSubview:iconView];
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.centerY.mas_equalTo(self).mas_offset(-50);
}];
UILabel *tipLabel = [[UILabel alloc] init];
tipLabel.text = title;
tipLabel.textColor = [UIColor colorWithHex:(0xCED3DB)];
tipLabel.font = [UIFont systemFontOfSize:14];
tipLabel.textAlignment = NSTextAlignmentCenter;
[contentView addSubview:tipLabel];
[tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self);
make.top.mas_equalTo(iconView.mas_bottom).mas_offset(20);
}];
}
-(void)removeEmptyDataSet: (BOOL)animated {
UIView *vw = [self viewWithTag:1280];
if (vw) {
for (UIView *v in vw.subviews) {
[v.layer removeAllAnimations];
}
if (animated) {
[UIView animateWithDuration:0.25 animations:^{
vw.alpha = 0;
} completion:^(BOOL finished) {
for (UIView *v in vw.subviews) {
[v removeFromSuperview];
}
[vw removeFromSuperview];
}];
} else {
vw.alpha = 0;
for (UIView *v in vw.subviews) {
[v removeFromSuperview];
}
[vw removeFromSuperview];
}
}
}
- (void)roundCorners: (UIRectCorner)corners radius: (CGFloat)radius {
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii: CGSizeMake(radius, radius)];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = maskPath.CGPath;
self.layer.mask = shape;
}
- (void)roundCorners: (UIRectCorner)corners radius: (CGFloat)radius bounds:(CGRect)bounds{
// CGRect bounds = CGRectMake(0, 0, KScreenWidth - 40, mycell.bounds.size.height);
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
/// SwifterSwift: Set some or all corners radiuses of view.
///
/// - Parameters:
/// - corners: array of corners to change (example: [.bottomLeft, .topRight]).
/// - radius: radius for selected corners.
//func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
// let maskPath = UIBezierPath(
// roundedRect: bounds,
// byRoundingCorners: corners,
// cornerRadii: CGSize(width: radius, height: radius))
//
// let shape = CAShapeLayer()
// shape.path = maskPath.cgPath
// layer.mask = shape
//}
-(void)roundCornersAllRadius:(CGFloat)radius{
self.layer.cornerRadius = radius;
self.layer.masksToBounds = YES;
}
@end
//
// UIView+HExtension.h
// ExerciseAnimation
//
// Created by L.mac on 2019/5/6.
// Copyright © 2019 L.mac. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (HExtension)
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY;
@property (nonatomic) CGPoint origin;
@property (nonatomic) CGSize size;
@end
NS_ASSUME_NONNULL_END
//
// UIView+HExtension.m
// ExerciseAnimation
//
// Created by L.mac on 2019/5/6.
// Copyright © 2019 L.mac. All rights reserved.
//
#import "UIView+HExtension.h"
@implementation UIView (HExtension)
- (CGFloat)x{
return self.frame.origin.x;
}
- (void)setX:(CGFloat)x{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
- (CGFloat)y{
return self.frame.origin.y;
}
- (void)setY:(CGFloat)y{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
- (CGFloat)width{
return self.frame.size.width;
}
- (void)setWidth:(CGFloat)width{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
- (CGFloat)height{
return self.frame.size.height;
}
- (void)setHeight:(CGFloat)height{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
- (CGFloat)centerX{
return self.center.x;
}
- (void)setCenterX:(CGFloat)centerX{
self.center = CGPointMake(centerX, self.center.y);
}
- (CGFloat)centerY{
return self.center.y;
}
- (void)setCenterY:(CGFloat)centerY{
self.center = CGPointMake(self.center.x, centerY);
}
- (CGPoint)origin{
return self.frame.origin;
}
- (void)setOrigin:(CGPoint)origin{
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
}
- (CGSize)size{
return self.frame.size;
}
- (void)setSize:(CGSize)size{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}
@end
//
// ESLyhXibView.h
// easysleep
//
// Created by Apple on 2020/9/9.
// Copyright © 2020 easy sleep. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIView+WHView.h"
NS_ASSUME_NONNULL_BEGIN
@interface ESLyhXibView : UIView
@end
NS_ASSUME_NONNULL_END
//
// ESLyhXibView.m
// easysleep
//
// Created by Apple on 2020/9/9.
// Copyright © 2020 easy sleep. All rights reserved.
//
#import "ESLyhXibView.h"
#import "UIView+AdaptScreen.h"
@implementation ESLyhXibView
- (void)awakeFromNib{
[super awakeFromNib];
[self adaptScreenWidthWithType:AdaptScreenWidthTypeAll exceptViews:nil];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
//
// UIView+AdaptScreenWidth.h
// TestXib
//
// Created by lbs on 2018/8/14.
// Copyright © 2018年 by. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, AdaptScreenWidthType) {
AdaptScreenWidthTypeConstraint = 1<<0, /**< 对约束的constant等比例 */
AdaptScreenWidthTypeFontSize = 1<<1, /**< 对字体等比例 */
AdaptScreenWidthTypeCornerRadius = 1<<2, /**< 对圆角等比例 */
AdaptScreenWidthTypeAll = 1<<3, /**< 对现有支持的属性等比例 */
};
@interface UIView (AdaptScreen)
/**
* 给UIView 设置圆角
*/
@property (assign,nonatomic) IBInspectable NSInteger cornerRadius;
@property (assign,nonatomic) IBInspectable BOOL masksToBounds;
/**
* 设置 view的 边框颜色(选择器和Hex颜色)
* 以及 边框的宽度
*/
@property (assign,nonatomic) IBInspectable NSInteger borderWidth;
@property (strong,nonatomic) IBInspectable NSString *borderHexRgb;
@property (strong,nonatomic) IBInspectable UIColor *borderColor;
/**
遍历当前view对象的subviews和constraints,对目标进行等比例换算
@param type 想要和基准屏幕等比例换算的属性类型
@param exceptViews 需要对哪些类进行例外
*/
- (void)adaptScreenWidthWithType:(AdaptScreenWidthType)type
exceptViews:(NSArray<Class> *)exceptViews;
@end
//
// UIView+AdaptScreenWidth.m
// TestXib
//
// Created by lbs on 2018/8/14.
// Copyright © 2018年 by. All rights reserved.
//
#import "UIView+AdaptScreen.h"
// 基准屏幕宽度
#define kRefereWidth 375.0
// 以屏幕宽度为固定比例关系,来计算对应的值。假设:基准屏幕宽度375,floatV=10;当前屏幕宽度为750时,那么返回的值为20
#define AdaptW(floatValue) (floatValue*[[UIScreen mainScreen] bounds].size.width/kRefereWidth)
@implementation UIView (AdaptScreen)
- (void)adaptScreenWidthWithType:(AdaptScreenWidthType)type
exceptViews:(NSArray<Class> *)exceptViews {
if (![self isExceptViewClassWithClassArray:exceptViews]) {
// 是否要对约束进行等比例
BOOL adaptConstraint = ((type & AdaptScreenWidthTypeConstraint) || type == AdaptScreenWidthTypeAll);
// 是否对字体大小进行等比例
BOOL adaptFontSize = ((type & AdaptScreenWidthTypeFontSize) || type == AdaptScreenWidthTypeAll);
// 是否对圆角大小进行等比例
BOOL adaptCornerRadius = ((type & AdaptScreenWidthTypeCornerRadius) || type == AdaptScreenWidthTypeAll);
// 约束
if (adaptConstraint) {
[self.constraints enumerateObjectsUsingBlock:^(__kindof NSLayoutConstraint * _Nonnull subConstraint, NSUInteger idx, BOOL * _Nonnull stop) {
subConstraint.constant = AdaptW(subConstraint.constant);
}];
}
// 字体大小
if (adaptFontSize) {
if ([self isKindOfClass:[UILabel class]] && ![self isKindOfClass:NSClassFromString(@"UIButtonLabel")]) {
UILabel *labelSelf = (UILabel *)self;
labelSelf.font = [UIFont systemFontOfSize:AdaptW(labelSelf.font.pointSize)];
}
else if ([self isKindOfClass:[UITextField class]]) {
UITextField *textFieldSelf = (UITextField *)self;
textFieldSelf.font = [UIFont systemFontOfSize:AdaptW(textFieldSelf.font.pointSize)];
}
else if ([self isKindOfClass:[UIButton class]]) {
UIButton *buttonSelf = (UIButton *)self;
buttonSelf.titleLabel.font = [UIFont systemFontOfSize:AdaptW(buttonSelf.titleLabel.font.pointSize)];
}
else if ([self isKindOfClass:[UITextView class]]) {
UITextView *textViewSelf = (UITextView *)self;
textViewSelf.font = [UIFont systemFontOfSize:AdaptW(textViewSelf.font.pointSize)];
}
}
// 圆角
if (adaptCornerRadius) {
if (self.layer.cornerRadius) {
self.layer.cornerRadius = AdaptW(self.layer.cornerRadius);
}
}
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull subView, NSUInteger idx, BOOL * _Nonnull stop) {
// 继续对子view操作
[subView adaptScreenWidthWithType:type exceptViews:exceptViews];
}];
}
}
// 当前view对象是否是例外的视图
- (BOOL)isExceptViewClassWithClassArray:(NSArray<Class> *)classArray {
__block BOOL isExcept = NO;
[classArray enumerateObjectsUsingBlock:^(Class _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([self isKindOfClass:obj]) {
isExcept = YES;
*stop = YES;
}
}];
return isExcept;
}
//xib配置属性
- (void)setCornerRadius:(NSInteger)cornerRadius
{
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = cornerRadius > 0;
}
- (NSInteger)cornerRadius
{
return self.layer.cornerRadius;
}
- (void)setBorderWidth:(NSInteger)borderWidth
{
self.layer.borderWidth = borderWidth;
}
- (NSInteger)borderWidth
{
return self.layer.borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor
{
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor
{
return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (void)setBorderHexRgb:(NSString *)borderHexRgb
{
NSScanner *scanner = [NSScanner scannerWithString:borderHexRgb];
unsigned hexNum;
//这里是将16进制转化为10进制
if (![scanner scanHexInt:&hexNum])
return;
self.layer.borderColor = [self colorWithRGBHex:hexNum].CGColor;
}
-(NSString *)borderHexRgb
{
return @"0xffffff";
}
- (void)setMasksToBounds:(BOOL)bounds
{
self.layer.masksToBounds = bounds;
}
- (BOOL)masksToBounds
{
return self.layer.masksToBounds;
}
- (UIColor *)colorWithRGBHex:(UInt32)hex
{
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
@end
//
// UIView+WHView.h
// WHKit
// https://github.com/remember17/WHKit
// Created by 吴浩 on 2017/6/7.
// Copyright © 2017年 remember17. All rights reserved.
// http://www.jianshu.com/p/c935314b078e
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, AutoresizingType) {
AutoresizingType_None,//不需要动态适配
AutoresizingType_TopMargin,//需要view顶部动态变化
AutoresizingType_BottomMargin,//需要view底部动态变化
AutoresizingType_Height //需要view高度动态变化
};
typedef void (^TapActionBlock)(UITapGestureRecognizer *gestureRecoginzer);
typedef void (^LongPressActionBlock)(UILongPressGestureRecognizer *gestureRecoginzer);
@interface UIView (WHView)
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
//截取成图片
- (UIImage *)wh_snapshotImage;
/**
* @brief 添加tap手势
*
* @param block 代码块
*/
- (void)wh_addTapActionWithBlock:(TapActionBlock)block;
/**
* @brief 添加长按手势
*
* @param block 代码块
*/
- (void)wh_addLongPressActionWithBlock:(LongPressActionBlock)block;
/** 找到指定类名的subView */
- (UIView *)wh_findSubViewWithClass:(Class)clazz;
- (NSArray *)wh_findAllSubViewsWithClass:(Class)clazz;
/** 找到指定类名的superView对象 */
- (UIView *)wh_findSuperViewWithClass:(Class)clazz;
/** 找到view上的第一响应者 */
- (UIView *)wh_findFirstResponder;
/** 找到当前view所在的viewcontroler */
- (UIViewController *)wh_findViewController;
//所有子视图
- (NSArray *)wh_allSubviews;
//移除所有子视图
- (void)wh_removeAllSubviews;
//xib加载视图
+ (instancetype)wh_loadViewFromNib;
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName;
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner;
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle;
/**
* 给UIView 设置圆角
*/
@property (assign,nonatomic) IBInspectable NSInteger cornerRadius;
@property (assign,nonatomic) IBInspectable BOOL masksToBounds;
/**
* 设置 view的 边框颜色(选择器和Hex颜色)
* 以及 边框的宽度
*/
@property (assign,nonatomic) IBInspectable CGFloat borderWidth;
@property (strong,nonatomic) IBInspectable NSString *borderHexRgb;
@property (strong,nonatomic) IBInspectable UIColor *borderColor;
//设置顶部底部高度自动约束
- (void)setAutoresizingType:(AutoresizingType)type andIsAutoresizingHeight:(BOOL)isAutoresizingHeight;
- (void)clipCorner:(CGFloat)radii topLeft:(BOOL)topLeft andTopRight:(BOOL)topRight andBottomLeft:(BOOL)bottomLeft andBottomRight:(BOOL)bottomRight;
@end
//
// UIView+WHView.m
// WHKit
// https://github.com/remember17/WHKit
// Created by 吴浩 on 2017/6/7.
// Copyright © 2017年 remember17. All rights reserved.
//
#import "UIView+WHView.h"
#import <objc/runtime.h>
static char kActionHandlerTapBlockKey;
static char kActionHandlerTapGestureKey;
static char kActionHandlerLongPressBlockKey;
static char kActionHandlerLongPressGestureKey;
@implementation UIView (WHView)
- (void)setX:(CGFloat)x{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
- (CGFloat)x{
return self.frame.origin.x;
}
- (void)setY:(CGFloat)y{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
- (CGFloat)y{
return self.frame.origin.y;
}
- (void)setWidth:(CGFloat)width{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
- (CGFloat)width{
return self.frame.size.width;
}
- (void)setHeight:(CGFloat)height{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
- (CGFloat)height{
return self.frame.size.height;
}
- (void)setCenterX:(CGFloat)centerX{
CGPoint point = self.center;
point.x = centerX;
self.center = point;
}
- (CGFloat)centerX{
return self.center.x;
}
- (void)setCenterY:(CGFloat)centerY{
CGPoint point = self.center;
point.y = centerY;
self.center = point;
}
- (CGFloat)centerY{
return self.center.y;
}
- (void)setSize:(CGSize)size{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}
- (CGSize)size{
return self.frame.size;
}
- (void)wh_addTapActionWithBlock:(TapActionBlock)block
{
UITapGestureRecognizer *gesture = objc_getAssociatedObject(self, &kActionHandlerTapGestureKey);
if (!gesture)
{
gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleActionForTapGesture:)];
[self addGestureRecognizer:gesture];
objc_setAssociatedObject(self, &kActionHandlerTapGestureKey, gesture, OBJC_ASSOCIATION_RETAIN);
}
objc_setAssociatedObject(self, &kActionHandlerTapBlockKey, block, OBJC_ASSOCIATION_COPY);
}
- (void)handleActionForTapGesture:(UITapGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateRecognized)
{
TapActionBlock block = objc_getAssociatedObject(self, &kActionHandlerTapBlockKey);
if (block)
{
block(gesture);
}
}
}
- (void)wh_addLongPressActionWithBlock:(LongPressActionBlock)block
{
UILongPressGestureRecognizer *gesture = objc_getAssociatedObject(self, &kActionHandlerLongPressGestureKey);
if (!gesture)
{
gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleActionForLongPressGesture:)];
[self addGestureRecognizer:gesture];
objc_setAssociatedObject(self, &kActionHandlerLongPressGestureKey, gesture, OBJC_ASSOCIATION_RETAIN);
}
objc_setAssociatedObject(self, &kActionHandlerLongPressBlockKey, block, OBJC_ASSOCIATION_COPY);
}
- (void)handleActionForLongPressGesture:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateRecognized)
{
LongPressActionBlock block = objc_getAssociatedObject(self, &kActionHandlerLongPressBlockKey);
if (block)
{
block(gesture);
}
}
}
- (UIView *)wh_findSubViewWithClass:(Class)clazz;
{
for (UIView * subView in self.subviews)
{
if ([subView isKindOfClass:clazz])
{
return subView;
}
}
return nil;
}
- (NSArray *)wh_findAllSubViewsWithClass:(Class)clazz
{
NSMutableArray *array = [NSMutableArray array];
for (UIView * subView in self.subviews)
{
if ([subView isKindOfClass:clazz])
{
[array addObject:subView];
}
}
return array;
}
- (UIView *)wh_findSuperViewWithClass:(Class)clazz;
{
if (self == nil)
{
return nil;
}
else if (self.superview == nil)
{
return nil;
}
else if ([self.superview isKindOfClass:clazz])
{
return self.superview;
}
else
{
return [self.superview wh_findSuperViewWithClass:clazz];
}
}
- (UIView *)wh_findFirstResponder
{
if (([self isKindOfClass:[UITextField class]] || [self isKindOfClass:[UITextView class]])
&& (self.isFirstResponder))
{
return self;
}
for (UIView *v in self.subviews)
{
UIView *fv = [v wh_findFirstResponder];
if (fv)
{
return fv;
}
}
return nil;
}
- (UIViewController *)wh_findViewController;
{
UIResponder *responder = self.nextResponder;
do
{
if ([responder isKindOfClass:[UIViewController class]])
{
return (UIViewController *)responder;
}
responder = responder.nextResponder;
}
while (responder);
return nil;
}
- (void)wh_removeAllSubviews
{
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
- (NSArray *)wh_allSubviews
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
[array addObjectsFromArray:self.subviews];
for (UIView *view in self.subviews)
{
[array addObjectsFromArray:[view wh_allSubviews]];
}
return array;
}
+ (instancetype)wh_loadViewFromNib
{
return [self wh_loadViewFromNibWithName:NSStringFromClass([self class])];
}
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName
{
return [self wh_loadViewFromNibWithName:nibName owner:nil];
}
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner
{
return [self wh_loadViewFromNibWithName:nibName owner:owner bundle:[NSBundle mainBundle]];
}
+ (instancetype)wh_loadViewFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle
{
UIView *result = nil;
NSArray* elements = [bundle loadNibNamed:nibName owner:owner options:nil];
for (id object in elements)
{
if ([object isKindOfClass:[self class]])
{
result = object;
break;
}
}
return result;
}
- (void)setCornerRadius:(NSInteger)cornerRadius
{
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = cornerRadius > 0;
}
- (NSInteger)cornerRadius
{
return self.layer.cornerRadius;
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
self.layer.borderWidth = borderWidth;
}
- (CGFloat)borderWidth
{
return self.layer.borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor
{
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor
{
return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (void)setBorderHexRgb:(NSString *)borderHexRgb
{
NSScanner *scanner = [NSScanner scannerWithString:borderHexRgb];
unsigned hexNum;
//这里是将16进制转化为10进制
if (![scanner scanHexInt:&hexNum])
return;
self.layer.borderColor = [self colorWithRGBHex:hexNum].CGColor;
}
-(NSString *)borderHexRgb
{
return @"0xffffff";
}
- (void)setMasksToBounds:(BOOL)bounds
{
self.layer.masksToBounds = bounds;
}
- (BOOL)masksToBounds
{
return self.layer.masksToBounds;
}
- (UIColor *)colorWithRGBHex:(UInt32)hex
{
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
- (UIImage *)wh_snapshotImage {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
- (void)setAutoresizingType:(AutoresizingType)type andIsAutoresizingHeight:(BOOL)isAutoresizingHeight{
UIViewAutoresizing viewAutoresizing;
switch (type) {
case AutoresizingType_TopMargin:
viewAutoresizing = UIViewAutoresizingFlexibleBottomMargin;
break;
case AutoresizingType_BottomMargin:
viewAutoresizing = UIViewAutoresizingFlexibleTopMargin;
break;
default:
viewAutoresizing = UIViewAutoresizingNone;
break;
}
self.autoresizingMask = viewAutoresizing;
if (isAutoresizingHeight == YES) {
self.autoresizingMask = viewAutoresizing | UIViewAutoresizingFlexibleHeight;
}
}
//切除指定圆角
- (void)clipCorner:(CGFloat)radii topLeft:(BOOL)topLeft
andTopRight:(BOOL)topRight
andBottomLeft:(BOOL)bottomLeft
andBottomRight:(BOOL)bottomRight
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(topLeft==YES ? UIRectCornerTopLeft : 0) |
(topRight==YES ? UIRectCornerTopRight : 0) |
(bottomLeft==YES ? UIRectCornerBottomLeft : 0) |
(bottomRight==YES ? UIRectCornerBottomRight : 0)
cornerRadii:CGSizeMake(radii, radii)];
// 创建遮罩层
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath; // 轨迹
self.layer.mask = maskLayer;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment