lzlGetInit
- (instancetype)init {
if (self == [super init]) {
[self setupUI];
}
return self;
}
- (void)setupUI {
}
lzlGetCancelButton
- (void)cancelButtonAction {
NSLog(@"%s",__FUNCTION__);
}
- (UIButton *)cancelButton {
if (!_cancelButton) {
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[_cancelButton setTitleColor:[UIColor hexStringToColor:@"#FFFFFF"] forState:UIControlStateNormal];
_cancelButton.backgroundColor = [UIColor hexStringToColor:@"#A7A7A7"];
_cancelButton.layer.cornerRadius = 17.5;
_cancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
[_cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelButton;
}
lzlGetGlobalQueue
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
lzlGetNavigationController
- (void)setupUI {
ViewController * vc = [[ViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
UINavigationController * NC = [self addChildVc:vc title:@"" image:@"" selectedImage:@""];
self.viewControllers = @[NC];
}
#pragma mark - 添加子控制器 设置图片
/**
* 添加一个子控制器
*
* @param childVc 子控制器
* @param title 标题
* @param image 图片
* @param selectedImage 选中的图片
*/
- (UINavigationController*)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
// 设置子控制器的文字
childVc.title = title; // 同时设置tabbar和navigationBar的文字
// 设置子控制器的图片
childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//未选中字体颜色 system为系统字体
[childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor],NSFontAttributeName:[UIFont fontWithName:nil size:13]} forState:UIControlStateNormal];
//选中字体颜色
[childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont fontWithName:nil size:13]} forState:UIControlStateSelected];
// 先给外面传进来的小控制器 包装 一个导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
return nav;
}
#pragma mark - 类的初始化方法,只有第一次使用类的时候会调用一次该方法
+ (void)initialize {
//tabbar去掉顶部黑线
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
}
lzlGetWindowScene
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.view.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
lzlGetAlertController
UIAlertController *alertCTL = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"单笔交易金额不能超过五万!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertCTL addAction:cancelAction];
[alertCTL addAction:okAction];
[self presentViewController:alertCTL animated:YES completion:nil];
lzlGetASButton
- (ASButton *)<#asbutton#> {
if (!<#_asbutton#>) {
<#_asbutton#> = [[ASButton alloc] init];
<#_asbutton#>.buttonStyle = ASButtonImageRight;
<#_asbutton#>.padding = 5;
<#_asbutton#>.backgroundColor = KMainLoginOutColor;
<#_asbutton#>.layer.cornerRadius = 17.5;
<#_asbutton#>.titleLabel.font = [UIFont systemFontOfSize:14];
[<#_asbutton#> setImage:[UIImage imageNamed:@"click_to_go_official_website_button_icon"] forState:UIControlStateNormal];
[<#_asbutton#> setTitle:@"点击前往官网" forState:UIControlStateNormal];
[<#_asbutton#> addTarget:self action:@selector(clickToGoOfficialWebsiteButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return <#_asbutton#>;
}
lzlGetBackFunction
- (void)backAction{
[self dismissViewControllerAnimated:YES completion:nil];
}
lzlGetBlockOperation
typedef void (^<# blockName #>)(<# type #> *<# name #>);
@property (nonatomic, <# type #>) void (^<# blockName #>)(<# type #> *<# name #>);
- (void)dataSourceWith<# blockName #>Operation:(void (^)(<# type #> * <# name #>))<# blockName #>Operation;
lzlGetButton
- (void)<# lzlbutton #>Action {
NSLog(@"%s",__FUNCTION__);
}
- (UIButton *)<# lzlbutton #> {
if (!_<# lzlbutton #>) {
_<# lzlbutton #> = [[UIButton alloc] init];
[_<# lzlbutton #> setTitleColor:<# lzlcolor #> forState:UIControlStateNormal];
[_<# lzlbutton #> setTitle:<# title #> forState:UIControlStateNormal];
_<# lzlbutton #>.titleLabel.font = [UIFont systemFontOfSize:<# size #>];
[_<# lzlbutton #> addTarget:self action:@selector(<# lzlbutton #>Action) forControlEvents:UIControlEventTouchUpInside];
}
return _<# lzlbutton #>;
}
lzlGetCloseButton
// 关闭弹窗
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"live_room_popoview_close_img"] forState:UIControlStateNormal];
[_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
lzlGetClosewhitebutton
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"live_room_popoview_close_img_white"] forState:UIControlStateNormal];
[_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
lzlGetCollectionViewDelegate
#pragma mark- UIColloctionViewDelegate
// 返回组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
// 返回每组当中所有的元素个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 12;
}
// 返回每个元素所使用的UICollectionViewCell对象
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//去复用队列中查找cell
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
//改变背景色
cell.backgroundColor = [UIColor orangeColor];
return cell;
}
// 修改每一个item的宽度和高度
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(100, 100);
}
// 返回每一组元素跟屏幕4个边界的距离(上,左,下,右)
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
//创建一个UIEdgeInsets的结构体
return UIEdgeInsetsMake(10, 10, 10, 10);
}
// 返回头部视图的宽和高
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
//注意:如果是竖直滑动,则只有高度有效,如果是水平滑动,则只有宽度有效
return CGSizeMake(50, 50);
}
// 返回头部和尾部视图所使用的UICollectionReusableView对象
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
//由于头部和尾部视图的实例化都需要调用此方法,所以需要通过kind判断生成的是头部视图还是尾部视图
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
//表示需要创建头部视图
//复用形式创建头部视图
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
//改变背景色
headerView.backgroundColor = [UIColor greenColor];
return headerView;
}
return nil;
}
// 选中某一个item
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"第%ld组第%ld个",indexPath.section,indexPath.item);
}
// 效果同layout.minimumLineSpacing,二选一
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
//
//}
// 效果同layout.minimumInteritemSpacing,二选一
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
//
//
//}
lzlGetFunction
- (<# type #>)<# functionName #>{
<# Initialization code #>
}
lzlGetDocument
#pragma mark- 获取沙盒路径
/// Document:
- (NSString *)getDocumentPathFunction {
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
return path;
}
/// Library:
- (NSString *)getLibraryPathFunction {
NSString *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject;
return path;
}
/// Caches:
- (NSString *)getCachesPathFunction {
NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
return path;
}
/// Preferences:
- (NSString *)getPreferencesPathFunction {
NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"Preferences"];
return path;
}
/// Temp:
- (NSString *)getTempPathFunction {
NSString *path = NSTemporaryDirectory();
return path;
}
lzlGetInitCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
<# Initialization code #>
}
return self;
}
lzlGetCollectionView
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumInteritemSpacing = 40;
layout.minimumLineSpacing = 5;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.bounces = YES;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.userInteractionEnabled = YES;
_collectionView.backgroundColor = [UIColor clearColor];
// 默认选中第一个元素
[_collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
[_collectionView registerClass:[ASCollectionViewCell class] forCellWithReuseIdentifier:[ASCollectionViewCell cellIdentifier]];
}
return _collectionView;
}
lzlGetTypeNameWithDict
- (instancetype)init<# TypeName #>WithDict:(NSDictionary *)dict {
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+ (instancetype)<# typeName #>WithDict:(NSDictionary *)dict {
return [[self alloc] init<# TypeName #>WithDict:dict];
}
lzlGetInitWithFrame
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
}
return self;
}
lzlGetKeyWindow
+ (UIWindow *)keyWindow {
UIWindow *foundWindow = nil;
NSArray *windows = [[UIApplication sharedApplication] windows];
for (UIWindow *window in windows) {
if (window.isKeyWindow) {
foundWindow = window;
break;
}
}
return foundWindow;
}
lzlGetKVC
- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues {
// 遍历字典
for (NSString *key in keyedValues) {
[self setValue:keyedValues[key] forKey:key];
}
}
// 重写
- (void)setValue:(id)value forKey:(NSString *)key {
if ([value isKindOfClass:[NSNumber class]]) {
[self setValue:[NSString stringWithFormat:@"%@",value] forKey:key];
} else if ([value isKindOfClass:[NSNull class]]) {
[self setValue:nil forKey:key];
} else {
[super setValue:value forKey:key];
}
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
if ([key isEqualToString:@"description"]) {
[self setValue:value forKey:@"myDescription"];
} else {
NSLog(@"未找到对应的key值:%@",key);
}
}
- (id)valueForUndefinedKey:(NSString *)key {
NSLog(@"未找到对应的key值:%@",key);
return nil;
}
lzlGetLazying
- <# name #>{
if (!_<# name #>) {
_<# name #> = [[<# type #> alloc] init];
}
return _<# name #>;
}
lzlGetLogFuncation
NSLog(@"%s",__FUNCTION__);
lzlGetLogPrint
NSLog(@"¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥");
lzlGetLogXing
NSLog(@"******************************************************");
lzlGetMark
#pragma mark-
lzlGetPickerViewDelegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 3;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:@"row number %ld",row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.myLabel.text = [NSString stringWithFormat:@"row number %ld",row];
}
lzlGetPopoview
@interface <#popoview#> ()
@property (nonatomic, strong) UIView * mainBGView;
@property (nonatomic, strong) UIView * contentBGView;
@property (nonatomic, strong) UIButton * closeButton;
@end
static <#popoview#> *<#_popoviewManager#> = nil;
@implementation <#popoview#>
- (instancetype)<#popoview#> {
if (self == [super init]) {
[self setupUI];
}
return self;
}
+ (instancetype)<#popoview#> {
if (<#_popoviewManager#> == nil) {
<#_popoviewManager#> = [[self alloc] <#popoview#>];
<#_popoviewManager#>.frame = [UIScreen mainScreen].bounds;
<#_popoviewManager#>.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
UIWindow *keyWindow = [ASKeyWindow keyWindow];
[keyWindow addSubview:<#_popoviewManager#>];
}
return <#_popoviewManager#>;
}
- (void)setupUI {
[self addSubview:self.mainBGView];
[self.mainBGView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(780, 520));
}];
[self.mainBGView addSubview:self.contentBGView];
[self.contentBGView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mainBGView).offset(15);
make.top.mas_equalTo(self.mainBGView).offset(15);
make.right.mas_equalTo(self.mainBGView).offset(-15);
make.bottom.mas_equalTo(self.mainBGView).offset(-15);
}];
[self.contentBGView addSubview:self.closeButton];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentBGView).offset(-11);
make.top.mas_equalTo(self.contentBGView).offset(11);
make.size.mas_equalTo(CGSizeMake(16.5, 16.5));
}];
}
#pragma mark- function
+ (void)hiddenChangeTextbookOrCoursewarePopoView {
[_changeTextbookOrCoursewarePopoViewManager removeFromSuperview];
_changeTextbookOrCoursewarePopoViewManager = nil;
}
- (void)hiddenChangeTextbookOrCoursewarePopoView {
[_changeTextbookOrCoursewarePopoViewManager removeFromSuperview];
_changeTextbookOrCoursewarePopoViewManager = nil;
}
- (void)closeButtonAction {
[self hiddenChangeTextbookOrCoursewarePopoView];
}
#pragma mark- lazying
- (UIView *)mainBGView {
if (!_mainBGView) {
_mainBGView = [[UIView alloc] init];
_mainBGView.layer.cornerRadius = 15;
_mainBGView.backgroundColor = KMainBorderColor;
}
return _mainBGView;
}
- (UIView *)contentBGView {
if (!_contentBGView) {
_contentBGView = [[UIView alloc] init];
_contentBGView.layer.cornerRadius = 10;
_contentBGView.backgroundColor = KMainBGViewColor;
}
return _contentBGView;
}
// 关闭弹窗
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"live_room_popoview_close_img"] forState:UIControlStateNormal];
[_closeButton addTarget:self action:@selector(closeButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
lzlGetPrefixHeader_pch
// 项目通用配置头文件
#pragma mark- APP
#define kAppBundleName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
#define kAppDisplayName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define kAppBundleVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 手机序列号 设备唯一标识符
#define kUUIDString [[[UIDevice currentDevice] identifierForVendor] UUIDString]
// 手机别名: 用户定义的名称
#define kUserPhoneName [[UIDevice currentDevice] name]
// 设备名称
#define kDeviceName [[UIDevice currentDevice] systemName]
// 手机系统版本
#define kPhoneVersion [[UIDevice currentDevice] systemVersion]
// 手机型号
#define kPhoneModel [[UIDevice currentDevice] model]
// 地方型号 (国际化区域名称)
#define kLocalPhoneModel [[UIDevice currentDevice] localizedModel]
#pragma mark- 日志打印输出
#ifdef DEBUG
#define ADLog(...) NSLog(__VA_ARGS__)
#else
#define ADLog(...) do {} while (0)
#endif
#ifdef DEBUG
#define DLog(...) NSLog(__VA_ARGS__)
#define debugMethod() NSLog(@"%s", __func__)
#else
#define DLog(...)
#define debugMethod()
#endif
/** 调试模式下输入NSLog,发布后不再输入 (打印信息包括 文件名 + 打印行数 + 打印方法 + 打印内容) */
#if DEBUG
#define Log(FORMAT, ...) fprintf(stderr, "\n----------------- NSLog start -----------------\n[文件名:%s] : [行号:%d]\n[函数名:%s]\n%s\n----------------- NSLog end -------------------\n", [[[NSString stringWithUTF8String: __FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat: FORMAT, ## __VA_ARGS__] UTF8String]);
#else
#define Log(FORMAT, ...)
#define debugMethod()
#endif
#pragma mark- https
#define HTTPS_MACRO 1
#define sHttp HTTPS_MACRO ? @"https" : @"http"
#define sPort HTTPS_MACRO ? @"443" : @"80"
#define isHTTPS HTTPS_MACRO ? @"YES" : @"NO"
#pragma mark- 色值设置
#define RGBColor(rgb) ([[UIColor alloc] initWithRed:(((rgb >> 16) & 0xff) / 255.0f) green:(((rgb >> 8) & 0xff) / 255.0f) blue:(((rgb) & 0xff) / 255.0f) alpha:1.0f])
#define RGBAColor(rgb,a) ([[UIColor alloc] initWithRed:(((rgb >> 16) & 0xff) / 255.0f) green:(((rgb >> 8) & 0xff) / 255.0f) blue:(((rgb) & 0xff) / 255.0f) alpha:a])
#define HexRGBColor(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]
#define RGB(r, g, b) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]
#define RGBA(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)]
#define rgba(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)]
#pragma mark- 屏幕 尺寸
#define ScreenH [UIScreen mainScreen].bounds.size.height
#define ScreenW [UIScreen mainScreen].bounds.size.width
#pragma mark- iPhone iPad iPhone_X的判断
#define IS_IPHONE ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_X ((ScreenW == 812.0f) ? YES : NO)
#define IS_IPAD ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
#pragma mark- 导航栏高度
#define ADNavHeight (IS_IPHONE ? 45 : 60)
#pragma mark- 屏幕比例,相对pad 1024 * 768
#define Proportion (ScreenH/768.0)
#pragma mark- 系统判定
#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
#define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
#define iOS9_1Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.1f)
#define iOS10_0Later ([UIDevice currentDevice].systemVersion.floatValue >= 10.0f)
#pragma mark- 引用
#define ad_weakify(var) __weak typeof(var) weakSelf = var
#define ad_strongify(var) __strong typeof(var) strongSelf = var
#pragma mark- 字符串判断
#define ISSTRINGCLASS(IPHONESTR) ([[IPHONESTR class] isSubclassOfClass:[NSString class]] ? YES:NO) // 是否字符串
#define NOTNILSTRING(IPHONESTR) ((ISSTRINGCLASS(IPHONESTR) == YES) ? IPHONESTR:@"") // 如果不是字符串则设为空字符串
#define NOTNILSTRINGTOSTR(IPHONESTR,ToStr) ((ISSTRINGCLASS(IPHONESTR) == YES) ? IPHONESTR:ToStr)//如果不是字符串则设为指定字符串
#pragma mark - 适配处理
/** 屏幕宽高 */
#define kScreenSize ([UIScreen mainScreen].bounds.size)
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
/** 相当于4.7屏幕的比例 */
#define kGlobalRate ([UIScreen mainScreen].bounds.size.width/375.0f)
#define kGlobalRate1 ([UIScreen mainScreen].bounds.size.width/375.0f/2)
#define kPictureBookWidthScale ([UIScreen mainScreen].bounds.size.width/667.0f)
#define kPictureBookWScale (kScreenHeight/812.0f)
#define kPictureBookHScale (kScreenWidth/812.0f)
/** 状态栏高度 */
#define kStatusBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height)
/** 导航栏高度 */
#define kNavBarHeight 44.0
/** 底部导航栏高度 */
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 83 : 49)
/** 顶部视图高度 导航栏加状态栏高度*/
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
/** 距离底部安全区域高度 */
#define kSafeAreaBottomHeight (kStatusBarHeight > 20 ? 34 : 0)
#pragma mark - 快捷设置
#define kSetFrameY(view, newY) view.frame = CGRectMake(view.frame.origin.x, newY, view.frame.size.width, view.frame.size.height)
#define kSetFrameX(view, newX) view.frame = CGRectMake(newX, view.frame.origin.y, view.frame.size.width, view.frame.size.height)
#define kSetFrameH(view, newH) view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, newH)
#define kSetFrameW(view, newW) view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, newW, view.frame.size.height)
lzlGetScreenWidthAndHight
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height
lzlGetScrollViewDelegate
#pragma mark- UIScrollViewDelegate
// 准备开始拖拽
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
NSLog(@"scrollViewWillBeginDragging");
}
// 准备停止拖拽
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
NSLog(@"scrollViewWillEndDragging");
}
// 已经停止拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"scrollViewDidEndDragging");
}
// 准备开始减速
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewWillBeginDecelerating");
}
//已经停止减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"偏移量为%@",NSStringFromCGPoint(scrollView.contentOffset));
NSLog(@"scrollViewDidEndDecelerating");
}
// 滚动过程中一直调用的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// NSLog(@"偏移量为%@",NSStringFromCGPoint(scrollView.contentOffset));
// NSLog(@"scrollViewDidScroll");
}
// 允许点击状态栏滑动到顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
return YES;
}
// 已经滑动到顶部
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
//NSLog(@"scrollViewDidScrollToTop");
UIAlertController *alertCTL = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"已经滑到最顶" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertCTL addAction:cancelAction];
[alertCTL addAction:okAction];
[self presentViewController:alertCTL animated:YES completion:nil];
}
lzlGetSessionDataDelegate
#pragma mark -
// 1.接收到服务器的响应
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler {
NSLog(@"%s", __func__);
// 允许处理服务器的响应,才会继续接收服务器返回的数据
completionHandler(NSURLSessionResponseAllow);
// void (^)(NSURLSessionResponseDisposition)
}
// 2.接收到服务器的数据(可能会被调用多次)
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
NSLog(@"%s", __func__);
}
// 3.请求成功或者失败(如果失败,error有值)
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"%s", __func__);
}
lzlGetSessionDownloadDelegate
#pragma mark -
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"didCompleteWithError");
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes {
NSLog(@"didResumeAtOffset");
}
/**
* 每当写入数据到临时文件时,就会调用一次这个方法
* totalBytesExpectedToWrite:总大小
* totalBytesWritten: 已经写入的大小
* bytesWritten: 这次写入多少
*/
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
NSLog(@"--------%f", 1.0 * totalBytesWritten / totalBytesExpectedToWrite);
}
// 下载完毕就会调用一次这个方法
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
// 文件将来存放的真实路径
NSString *file = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:downloadTask.response.suggestedFilename];
// 剪切location的临时文件到真实路径
NSFileManager *mgr = [NSFileManager defaultManager];
[mgr moveItemAtURL:location toURL:[NSURL fileURLWithPath:file] error:nil];
}
lzlGetSetupUI
- (void)setupUI {
}
lzlGetSingleton
static id _instance = nil;
+ (instancetype)sharedInstance {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
});
return _instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
}
- (id)copyWithZone:(NSZone *)zone {
return _instance;
}
#if __has_feature(objc_arc)
// 编译器是ARC环境
#else
// 编译器是MRC环境
- (oneway void)release {
}
- (instancetype)retain {
return self;
}
- (instancetype)autorelease {
return self;
}
- (NSUInteger)retainCount {
return 1;
}
#endif
lzlGetSizeAttributedText
/// 计算带有行间距的文字的Size
/// @param text 传入的文字内容
/// @param font 字体大小
/// @param maxSize 最大显示尺寸
/// @param lineSpacing 设置行间距
/// @param kernAttributeName 设置字间距
- (CGSize)sizeAttributedTextWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize lineSpacing:(CGFloat)lineSpacing kernAttributeName:(CGFloat)kernAttributeName {
NSMutableParagraphStyle *paragraStyle = [[NSMutableParagraphStyle alloc] init];
paragraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paragraStyle.alignment = NSTextAlignmentLeft;
paragraStyle.lineSpacing = lineSpacing; // 设置行间距
paragraStyle.hyphenationFactor = 1.0;
paragraStyle.firstLineHeadIndent = 0.0;
paragraStyle.paragraphSpacingBefore = 0.0;
paragraStyle.headIndent = 0;
paragraStyle.tailIndent = 0;
// 设置字间距 NSKernAttributeName: @1.5f,
NSDictionary *dic = @{
NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraStyle,
NSKernAttributeName: @(kernAttributeName),
};
CGSize size = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
return size;
}
lzlGetSizeWithText
/// 计算文字尺寸
/// @param text 需要计算文字的尺寸
/// @param font 文字的字体
/// @param maxSize 文字的最大尺寸
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize {
NSDictionary *attrs = @{NSFontAttributeName : font};
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}
lzlGetTableViewDelegate
#pragma mark- UITableView代理
// 返回组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
// 返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//复用的形式创建
static NSString * const ID = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = @"大家好";
return cell;
}
// 返回组头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
// 自定义组头视图(必须要返回组头高度)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
[b setTitle:[NSString stringWithFormat:@"第%ld组组头",section] forState:UIControlStateNormal];
b.backgroundColor = [UIColor orangeColor];
//返回视图的高度一般要与组头高度一致
b.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
return b;
}
// 返回组尾高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 30;
}
// 自定义组尾视图(必须要返回高度)
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
view.backgroundColor = [UIColor blackColor];
return view;
}
lzlGetTextFieldDelegate
#pragma mark- UITextFieldDelegate
// 准备进入编辑状态
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"%p",textField);
//返回NO,无法进入编辑状态
return YES;
}
// 已经进入编辑状态
- (void)textFieldDidBeginEditing:(UITextField *)textField {
}
// 准备结束编辑状态
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"textFieldShouldEndEditing:%@",textField.text);
//返回NO,无法结束编辑状态
return YES;
}
// 已经结束编辑状态
- (void)textFieldDidEndEditing:(UITextField *)textField {
}
// 是否可以点击清理按钮
-(BOOL)textFieldShouldClear:(UITextField *)textField {
//返回NO,点击clear按钮无响应
return YES;
}
// 是否可以点击return按钮(无效)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
//收键盘
//移除第一响应者
[textField resignFirstResponder];
return YES;
}
// 是否允许修改内容
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
//string
NSLog(@"string = %@",string);
//textField上面的内容
NSLog(@"textField.text = %@",textField.text);
/*
if ([string isEqualToString:@"h"]) {
return NO;
}*/
if (textField.text.length >= 6) {
if ([string isEqualToString:@""]) {
return YES;
}
return NO;
}
return YES;
}
//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
//
// return [self validateNumber:string];
//}
//
//- (BOOL)validateNumber:(NSString*)number {
//
// BOOL res = YES;
// NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
// int i = 0;
// while (i < number.length) {
// NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
// NSRange range = [string rangeOfCharacterFromSet:tmpSet];
// if (range.length == 0) {
// res = NO;
// break;
// }
// i++;
// }
// return res;
//}
//
//#define NUMBERS @"0123456789"
//- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string {
//
// NSCharacterSet*cs;
// cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
// NSString*filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
// BOOL basicTest = [string isEqualToString:filtered];
// if(!basicTest) {
//
// UIAlertController *alertCTL = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请输入数字!" preferredStyle:UIAlertControllerStyleAlert];
//
// UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
// UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
// [alertCTL addAction:cancelAction];
// [alertCTL addAction:okAction];
// [self presentViewController:alertCTL animated:YES completion:nil];
//
// return NO;
// }
// return YES;
//}
lzlGetTypeProperty
@property (nonatomic, <# type #>) <# type #> * <# name #>;
lzlGetWeakSelf
__weak typeof(self) weakSelf = self;
lzlGetWebViewDelegate
#pragma mark -
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.backItem.enabled = webView.canGoBack;
self.forward.enabled = webView.canGoForward;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
self.backItem.enabled = webView.canGoBack;
self.forward.enabled = webView.canGoForward;
}
/**
* 每当webView即将发送一个请求之前,都会调用这个方法
* 返回YES:允许加载这个请求
* 返回NO:禁止加载这个请求
*/
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// NSLog(@"%@", request.URL);
if ([request.URL.absoluteString containsString:@"life"]) return NO;
// JS JavaScript
return YES;
}
lzlGetWindow
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[LZLViewController alloc] init]];
lzlGetAddScrollView
CGFloat viewMargin = 88;
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view).offset(viewMargin);
make.left.right.bottom.mas_equalTo(self.view);
}];
[self.scrollView addSubview:self.contentBGView];
[self.contentBGView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self.contentBGView addSubview:self.mainBGView];
[self.mainBGView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentBGView).offset(viewMargin);
make.right.mas_equalTo(self.contentBGView).offset(-viewMargin);
make.top.mas_equalTo(self.contentBGView);
make.height.mas_equalTo(941);
make.bottom.mas_equalTo(self.scrollView).with.offset(-20);
}];
lzlGetCategoryRunTime
#import "ADNewViewController+ADFunction.h"
#import
typedef void (^blockOperation)(BOOL isVip);
@interface ADNewViewController (ADFunction)
/// 回调信息
@property (nonatomic, copy) blockOperation blockOt;
/// 是否VIP用户
@property (nonatomic, assign) BOOL isVip;
/// 用户信息
@property (nonatomic, copy) NSString * userMessage;
/// 图片的尺寸大小
@property (nonatomic, assign) CGSize imageSize;
/// 改变背景颜色
- (void)changeBackgroudViewColor;
@end
static void *kADIsVipUserKey = @"kADIsVipUserKey"; // 是否VIP用户
static void *kADUserMessageKey = @"kADUserMessageKey"; // 用户信息
static void *kADBlockOperationKey = @"kADBlockOperationKey"; // 回调信息
static void *kADImageSizeKey = @"kADImageSizeKey"; // 图片的尺寸大小
@implementation ADNewViewController (ADFunction)
- (void)changeBackgroudViewColor {
self.isVip = !self.isVip;
if (self.isVip) {
self.view.backgroundColor = [UIColor redColor];
self.imageSize = CGSizeMake(400, 400);
self.userMessage = @"是VIP用户啊";
} else {
self.view.backgroundColor = [UIColor yellowColor];
self.imageSize = CGSizeMake(200, 200);
self.userMessage = @"是普通用户";
}
if (self.blockOt) {
self.blockOt(self.isVip);
}
}
#pragma mark- objc/runtime
// 回调信息
- (void)setBlockOt:(blockOperation)blockOt {
objc_setAssociatedObject(self, kADBlockOperationKey, blockOt, OBJC_ASSOCIATION_COPY);
}
- (blockOperation)blockOt {
return objc_getAssociatedObject(self, kADBlockOperationKey);
}
// 是否VIP用户
- (void)setIsVip:(BOOL)isVip {
objc_setAssociatedObject(self, kADIsVipUserKey, @(isVip), OBJC_ASSOCIATION_RETAIN);
}
- (BOOL)isVip {
return [objc_getAssociatedObject(self, kADIsVipUserKey) boolValue];
}
// 用户信息
- (void)setUserMessage:(NSString *)userMessage {
objc_setAssociatedObject(self, kADIsVipUserKey, userMessage, OBJC_ASSOCIATION_RETAIN);
}
- (NSString *)userMessage {
return objc_getAssociatedObject(self, kADUserMessageKey);
}
// 图片的尺寸大小
- (void)setImageSize:(CGSize)imageSize {
objc_setAssociatedObject(self, kADImageSizeKey, [NSValue valueWithCGSize:imageSize], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (CGSize)imageSize {
NSValue *value = objc_getAssociatedObject(self, kADImageSizeKey);
return value.CGSizeValue;
}
lzlGetPodfile
platform :ios,'<# vision #>'
target "<# projectName #>" do
pod 'Masonry'
end
lzlGetAddTableViewCellHeader
+ (NSString *)cellIdentifier;
+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath;
lzlGetAddTableViewCell
+ (NSString *)cellIdentifier {
static NSString *ID = @"<# cellIdentifier #>";
return ID;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
<# ADTableViewCell #> *cell = [tableView dequeueReusableCellWithIdentifier:[<# ADTableViewCell #> cellIdentifier] forIndexPath:indexPath];
if (!cell) {
cell = [[self alloc] initWithStyle:<# UITableViewCellStyleDefault #> reuseIdentifier:[<# ADTableViewCell #> cellIdentifier]];
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setupUI];
}
return self;
}
- (void)setupUI {
}
lzlGetAddCollectionViewCellHeader
+ (NSString *)cellIdentifier;
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath;
lzlGetAddCollectionViewCell
+ (NSString *)cellIdentifier {
static NSString *ID = @"<# cellIdentifier #>";
return ID;
}
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath {
<# ADCollectionViewCell #> *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[<# ADCollectionViewCell #> cellIdentifier] forIndexPath:indexPath];
if (!cell) {
cell = [[self alloc] initWithFrame:CGRectZero];
}
return cell;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self == [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
- (void) setupUI {
}
lzlGetCurrentViewController
#pragma mark -获取当前屏幕显示的ViewController
- (UIViewController *)getCurrentViewController {
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentViewController = [self getCurrentViewControllerFromRootViewController:rootViewController];
return currentViewController;
}
- (UIViewController *)getCurrentViewControllerFromRootViewController:(UIViewController *)rootViewController {
UIViewController *currentViewController;
if ([rootViewController presentedViewController]) {
rootViewController = [rootViewController presentedViewController];
}
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
currentViewController = [self getCurrentViewControllerFromRootViewController:[(UITabBarController *)rootViewController selectedViewController]];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
currentViewController = [self getCurrentViewControllerFromRootViewController:[(UINavigationController *)rootViewController visibleViewController]];
} else {
currentViewController = rootViewController;
}
return currentViewController;
}
lzlGetStringWidth
/// 计算字符串长度
/// @param string string
/// @param font font
- (CGFloat)getWidthWithString:(NSString *)string font:(UIFont *)font {
NSDictionary *attrs = @{NSFontAttributeName : font};
return [string boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width;
}
lzlGetRandomColor
/// 随机色
- (UIColor*) randomColor {
NSInteger r = arc4random() % 255;
NSInteger g = arc4random() % 255;
NSInteger b = arc4random() % 255;
return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:1];
}
lzlGetBezierPath
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:<#CGRect#> byRoundingCorners:UIRectCornerAllCorners cornerRadii:<#CGSize#>];
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
layer.frame = <#CGRect#>;
layer.path = path.CGPath;
<#propertyName#>.layer.mask = layer;