美文网首页
iOS常用代码块笔记

iOS常用代码块笔记

作者: 数字d | 来源:发表于2021-07-22 11:41 被阅读0次

1.时间戳和时间工具 yz_time

 NSDate *senddate = [NSDatedate];
        NSLog(@"date1时间戳 = %ld",time(NULL));
        NSString *date2 = [NSStringstringWithFormat:@"%ld", (long)[senddatetimeIntervalSince1970]];
        NSLog(@"date2时间戳 = %@",date2);
        NSDateFormatter *dateformatter = [[NSDateFormatteralloc] init];
        [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSString *date1 = [dateformatter stringFromDate:senddate];
        NSLog(@"获取当前时间   = %@",date1);
        // 时间戳转时间
        NSDate *confromTimesp = [NSDatedateWithTimeIntervalSince1970:[senddate timeIntervalSince1970]];
        NSString *confromTimespStr = [dateformatterstringFromDate:confromTimesp];
        NSLog(@"时间戳转时间   = %@",confromTimespStr);
// 两个时间戳的间隔   返回的是秒
        NSTimeInterval time = [now timeIntervalSinceDate:oldDate];
        NSLog(@"time:%f",time/60/60/24);

2.延时执行工具yz_delay

// 第一个参数:延迟的时间
// 可以通过改变队列来改变线程
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    // 需要延迟执行的代码
});

3.给view切一部分圆角yz_corner

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_topSelectView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15,15)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _topSelectView.bounds;
maskLayer.path = maskPath.CGPath;
_topSelectView.layer.mask = maskLayer;

4.tap点击手势 yz_tap

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editzafNameAction)];
tap.delegate = self;
[<#_m1editImg#> addGestureRecognizer:tap];

5单例的实现yz_instance

#import "<#HPMapLocationService#>.h"

static <#HPMapLocationService#> *instance = nil;

@interface <#HPMapLocationService#>()

@end

@implementation <#HPMapLocationService#>

+ (instancetype)sharedInstance
{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        instance = [[<#HPMapLocationService#> alloc] init];
        
    });
    
    return instance;
}

6.布尔值的属性创建
yz_bool

@property(nonatomic,assign)BOOL  <#selectStatus#>;

7.字符串的属性创建

@property(nonatomic,strong)NSString * <#bankNum#>;

8.cell.m的快速实现yz_cellm

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"YZFansTasksCell";
    // 1.缓存中取
    YZFansTasksCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
   if (cell == nil) {
        cell = [[YZFansTasksCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
    
}


/**
 *  构造方法(在初始化对象的时候会调用)
 *  一般在这个方法中添加需要显示的子控件
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

9.img的属性yz_img

@property(nonatomic,strong)UIImageView * <#zafImg#>;

10.label的属性

@property(nonatomic,strong)UILabel * <#monthNumLab#>;

11.button的懒加载lazybtn

-(UIButton *)<#editBtn#> {
    if (_<#editBtn#> == nil) {
        _<#editBtn#> = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _<#editBtn#>.frame = CGRectMake(0, 0, 0, 0);
        [_<#editBtn#> addTarget:self action:@selector(editAction) forControlEvents:(UIControlEventTouchUpInside)];
        [_<#editBtn#> setImage:[UIImage imageNamed:@"<#yz_zbing_icon_bj#>"] forState:(UIControlStateNormal)];
    }
    return _<#editBtn#>;
}

-(void)editAction {
    if (self.block) {
        self.block();
    }
}

12.label的懒加载lazylab

-(UILabel *)<#nameLab#> {
    if (_<#nameLab#> == nil) {
        _<#nameLab#> = [[UILabel alloc] init];
        _<#_detailLab#>.text = @"陪练下单 | 礼物打赏 | 兑换商品";
        _<#_detailLab#>.textAlignment = NSTextAlignmentLeft;
        _<#_detailLab#>.font = [UIFont systemFontOfSize:26];
        _<#_detailLab#>.font = [UIFont boldSystemFontOfSize:26];
        _<#_detailLab#>.textColor = UIColorHex(#FFFFFF);
    }
    return _<#nameLab#>;
}

13.mark提示mark

#pragma mark --------- <##>

14.方法注释 yz_detail

/**
 * <#获取直播间的公告信息#>
 */

15.创建一个空方法yz_function

-(void)<#configInnerUI#> {
    
}

16.json字符串转字典yz_json

NSData * data = [<#reason#> dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];

17.网络请求yz_request

//可自行根据每个项目进行补充

18.取消延时执行的代码yz_cancel

[self performSelector:@selector(<#function#>)
               withObject:nil
           afterDelay:<#3.0#>];

[NSObject cancelPreviousPerformRequestsWithTarget:self
                                             selector:@selector(<#function#>)
                                               object:nil];

-(void) <#function#> {
    
}

相关文章

  • iOS常用代码块笔记

    1.时间戳和时间工具 yz_time 2.延时执行工具yz_delay 3.给view切一部分圆角yz_corne...

  • iOS 常用代码块

    iOS 常用代码块: @property (nonatomic, strong) <#Class#> * <#ob...

  • iOS 常用代码块

    不定期添加和整理 如有帮助,点个喜欢可好? 目录 1. 扩大按钮点击范围(扩大点击事件响应范围) 富文本 2.1 ...

  • iOS 常用代码块

    刚在网上看到一篇关于 CodeSnippets 的文章,发现自己好像一直也是这样做的,但是从来没整理过的,So 利...

  • (iOS)常用的代码块

    使用很简单,在代码区域写入代码块,然后按住拖到右下角即可。 Title:代码块的标题Summary:代码块的描述文...

  • IOS --- 设置常用代码块

    我们经常遇到这样的问题,在不同的文件或者项目里面总会需要设置一些相同的代码,例如多次懒加载数组,多次设置视图颜色,...

  • iOS常用代码块Snippets

    属性 strong-pstrong weak-pweak copy-pcopy assign-passign bl...

  • iOS-常用代码块

    代码块(Snippet),方便了代码快速创建。 管理:在新版Xcode中管理页面在编译器的右上角 添加:选中代码鼠...

  • ios常用快捷代码块

    Xcode 代码块备份在更换自己用过电脑,或公司电脑与个人电脑中时,只要将~/Library/Developer/...

  • iOS开发之常用代码块

    持续更新中 设置TabBarController为Window的根视图 创建一个导航视图层级的TabBar子视图

网友评论

      本文标题:iOS常用代码块笔记

      本文链接:https://www.haomeiwen.com/subject/lkmemltx.html