Snippet-Xcode10快捷代码

迁移快捷代码

  • 打开 Finder,快捷键Command + Shift + G.弹出文本框.输入~/Library/Developer/Xcode/UserData/CodeSnippets(如果没有CodeSnippets 可以先自定义一个代码段 然后文件自动生成 如果是beta版本路径所有改变了)
  • image.png
  • 摘录

Xcode制作Snippets

制作代码段.png

代码段位置.png

可以用cmd+shift+l调试出来

  • 了解Snippets
    代码段图.png

1.Title:标题
2.Summary:备注
3.Completion Shortcut:快捷方式
4.Platform:平台(iOS)、Language:语言(Objective-C)

5.Completion Scopes:作用域


作用域.png
  • Class Implementation:类的实现区域(ViewDidLoad、ViewWillAppear同级)
  • Class Interface Methods:类的定义区域(@property(nonatomic,strong)NSString *name;同级)
  • Class Interface Variables:类定义区域的{}里面 定义常量({
    NSString *_name;
    } 同级)
    *Code Expression、Function or Method :都是在方法里面写
  • Preprocessor Directive(前置处理器指示词):在一些导入类的头文件下面写
  • String or Comment:不知道
  • Top Level :不知道
  • 隐式<#name#> 就是Xcode里面 需要填充的占位
  • 删除 选中按delete 就可以啦

代码段

1.属性

  • strong-pstrong
@property(nonatomic,strong)<#type#> *<#name#>;
  • copy-pcopy
@property(nonatomic,copy)<#type#> *<#name#>;
  • assign-passign
@property(nonatomic,assign)<#type#> <#name#>;
  • readonly-preadonly
@property(nonatomic,assign,readonly)<#type#> <#name#>;
  • delegate-pdelegate
@property(nonatomic,weak)id <<#delegatename#>> delegate;
  • block-pblock
@property(nonatomic,copy)void (^<#name#>)(<#type#> <#name#>);
  • weak-pweak
@property(nonatomic,weak)<#type#> *<#name#>;

2.mark

  • life生命区域-plife
#pragma mark - life生命区
  • lazy懒加载-plazy
#pragma mark - lazy懒加载
  • 通用-pmark
#pragma mark - <#内容#>

3.枚举值

  • 枚举-penum
typedef NS_ENUM(NSUInteger, <#MyEnum#>) {
    <#MyEnumValueA#>,
    <#MyEnumValueB#>,
    <#MyEnumValueC#>,
};

4.init

  • init-pinit
- (instancetype)init
{
    if (self = [super init]) {
        
    }
    return self;
}
  • initFrame-pinitFrame
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

6.if

  • if else- pifelse
if (<#判断条件#>) {
        
    } else if (<#判断条件#>) {
        
    } else {
        
    }

7.控件

  • UITableView-ptableview
- (UITableView *)mainView
{
    if (!_mainView) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
        [self.view addSubview:tableView];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tableFooterView = [UIView new];
        [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.rowHeight = 50;
        if (@available(iOS 11.0, *))
        {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        else
        {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        _mainView = tableView;
    }
    return _mainView;
}
  • UICollectionView-pcollectionview
- (UICollectionView *)mainView
{
    if (!_mainView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(74*ADAPTER_WIDTH, 118*ADAPTER_WIDTH);
        flowLayout.minimumLineSpacing = 12*ADAPTER_WIDTH;
        flowLayout.minimumInteritemSpacing = 0*ADAPTER_WIDTH;//就一行
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 10*ADAPTER_WIDTH, 0, 10*ADAPTER_WIDTH);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:flowLayout];
        [self.shadowView addSubview:collectionView];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
        collectionView.backgroundColor = [UIColor whiteColor];
        _mainView = collectionView;
    }
    return _mainView;
}
  • UILable-plabel
- (UILabel *)<#name#>
{
    if (!_<#name#>) {
        UILabel *lab = [[UILabel alloc]init];
        [self addSubview:lab];
        lab.font = [UIFont systemFontOfSize:<#(CGFloat)#> weight:<#(UIFontWeight)#>];
        lab.textColor = <#(nullable UIColor *)#>;
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
        _<#name#> = lab;
    }
    return _<#name#>;
}
  • UIButton-pbutton
- (UIButton *)<#name#>
{
    if (!_<#name#>) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        [button setTitle:<#(nullable NSString *)#> forState:<#(UIControlState)#>];
        [button setTitleColor:<#(nullable UIColor *)#> forState:<#(UIControlState)#>];
        button.titleLabel.font = [UIFont systemFontOfSize:<#(CGFloat)#> weight:<#(UIFontWeight)#>];
        [button setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>];
        [button addTarget:<#(nullable id)#> action:<#(nonnull SEL)#> forControlEvents:<#(UIControlEvents)#>];
        button.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
        _<#name#> = button;
    }
    return _<#name#>;
}

*UIView-pview

- (UIView *)<#name#>
{
    if (!_<#name#>) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = RGB(<#r#>, <#g#>, <#b#>, <#a#>);
        view.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
        _<#name#> = view;
    }
    return _<#name#>;
}

*UIImageView-pimageview

- (UIImageView *)<#name#>
{
    if (!_<#name#>) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self addSubview:iv];
        iv.image = [UIImage getPNGimageInBundleWithName:<#(NSString *)#>];
        iv.contentMode = <#(contentModel)#>;
        iv.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
        _<#name#> = iv;
    }
    return _<#name#>;
}

8.手势

  • 创建手势-ptapges
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(<#selector#>)];
<#view#>.userInteractionEnabled = YES;
[<#view#> addGestureRecognizer:tap];

9.layer

  • 圆角-playercorner
<#view#>.layer.cornerRadius = 20*ADAPTER_WIDTH;
<#view#>.layer.masksToBounds = YES;
  • 边-playerborder
<#view#>.layer.borderColor = RGB(<#r#>, <#g#>, <#b#>, <#a#>).CGColor;
<#view#>.layer.borderWidth = 1;
  • 阴影
self.layer.shadowColor = RGB(<##>, <##>, <##>, <##>).CGColor;
self.layer.shadowOffset = CGSizeMake(0, 0);
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 1;
  • 渐变色
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc]init];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(<#x#>.frame), CGRectGetHeight(<#x#>.frame));
        UIColor *startColor = rgba(254, 203, 67, 1);
        UIColor *endColor = rgba(255, 154, 56, 1);
        gradientLayer.colors = @[(__bridge id)startColor.CGColor,(__bridge id)endColor.CGColor];
        [<#x#>.layer addSublayer:gradientLayer];

10.网络请求

  • if esle-pifnet
NSLog(@"%@",model);
if (!error) {
    NSString *code = [NSString stringWithFormat:@"%@",model[@"code"]];
    NSString *message = [NSString stringWithFormat:@"%@",model[@"message"]];
    [weakSelf.view showWarning:message];
    if ([code isEqualToString:@"0"]) {
        
    } else {

    }
} else {
    [weakSelf.view showWarning:kbstTipNetError];
}

11.alert提示框

  • alert-palert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
}];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    
}];
[alert addAction:cancleAction];
[alert addAction:sureAction];
[cancleAction setValue:kColor86 forKeyPath:@"_titleTextColor"];
[sureAction setValue:RGB(87, 156, 58, 1) forKeyPath:@"_titleTextColor"];
[self presentViewController:alert animated:YES completion:nil];

12.浏览器

  • 浏览器-pbrowser
NSMutableArray *dataSource = [NSMutableArray array];
    for (NSInteger index = 0; index < self.detailModel.data.images.count; index ++) {
        YBImageBrowseCellData *cellData = [[YBImageBrowseCellData alloc]init];
        cellData.url = self.detailModel.data.images[index].wppURL;
        cellData.sourceObject = [carousel itemViewAtIndex:index];
        [dataSource addObject:cellData];
    }
    YBImageBrowser *yb = [[YBImageBrowser alloc]init];
    yb.dataSourceArray = dataSource;
    yb.currentIndex = index;
    [yb show];
    self.viewDidAppear = NO;
    WK(weakSelf)
    [yb setHideBlock:^{
        weakSelf.viewDidAppear = YES;
    }];

你可能感兴趣的:(Snippet-Xcode10快捷代码)