Update note: The following creation methods are applicable to xcode10 and later versions. The content introduction is not affected. For details about how to create XCODE10, see XCODE10 Code Block Creation Method
In fact, we often use when programming to the code block, just system has been packaged, dispatch, the init and its derivatives, for example, we often need only in a few key words according to need, press enter, the system will direct write code implementation of a complete set of, actually system is to use the packaging good code block, You can see some of the code blocks wrapped by the system on the right side of Xcode, as shown below
To create a new code snippet, select the code in the project and drag it to the area in Xcode indicated in the image below
Release the left mouse button, and a code snippet editing window will pop up, as shown below:
The meanings from top to bottom are as follows: ①Title the Title of the snippet ②Summary the description of the snippet ③Platform The Platform on which the snippet can be used ④Language Which languages are available for using the snippet ⑤Completion snippet shortcuts, for example: Which files can copy ⑥Completion Scopes use the current snippet in, such as all locations, medium header files, or multiple supported locations can be added. The last big blank area is the preview of the code snippet. Once everything is set up, click the Done button in the lower right corner of the menu to complete the creation.
##### Code snippet backup:
Code snippets in Xcode are placed in the following directory by default:
~/Library/Developer/Xcode/UserData/CodeSnippets
You can back up code snippets in your directory, or you can copy them directly and use them on different computers.
Here is the code snippet I used, pre-typed placeholder 1 UIView
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(<#NSObject#>, <#NSObject#>, <#NSObject#>, <#NSObject#>)];
view.backgroundColor=[UIColor whiteColor];
[<#NSObject#> addSubview:view];
Copy the code
2, UITextField at
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(<#NSObject#>,<#NSObject#>, <#NSObject#>, <#NSObject#>)];
textField.placeholder =<#NSObject#>;
textField.secureTextEntry = NO;
[textField setBorderStyle:UITextBorderStyleNone];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.delegate = self;
[<#NSObject#> addSubview:textField];
Copy the code
3, UITapGestureRecognizer
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(<#NSObject#>)];
[<#NSObject#> addGestureRecognizer:tap];
Copy the code
4, the UITableView
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(<#NSObject#>, <#NSObject#>, <#NSObject#>,<#NSObject#>)];TableView. BackgroundColor = [UIColor colorWithRed: green 1.0:1.0 blue: alpha 1.0:1); tableView.bounces=YES; tableView.delegate = self; tableView.dataSource = self; [<#NSObject#> addSubview:tableView];
Copy the code
5, UIScrollView
UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(<#NSObject#>,<#NSObject#>, <#NSObject#>,<#NSObject#>)];
scrollView.backgroundColor=[UIColor <#NSObject#>];
scrollView.contentSize=CGSizeMake(<#NSObject#>,<#NSObject#>);
scrollView.bounces=YES;
scrollView.pagingEnabled=YES;
scrollView.scrollEnabled=YES;
[<#NSObject#> addSubview:scrollView];
Copy the code
6, the property
@property(strong,readwrite,nonatomic)<#NSObject#> *<#NSObject#>;
Copy the code
7. Dividing line
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * (#NSObject#>****************************************/
Copy the code
8 NSMutableDictionary.
NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
Copy the code
9 NSMutableArray.
NSMutableArray *array=[[NSMutableArray alloc]init];
Copy the code
10, UILabel
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(<#NSObject#>, <#NSObject#>, <#NSObject#>, <#NSObject#>)];
lable.text=<#NSObject#>;
lable.textColor=[UIColor <#NSObject#>];
lable.font=[UIFont systemFontOfSize:<#NSObject#>];
lable.textAlignment=NSTextAlignmentLeft;
[<#NSObject#> addSubview:lable];
Copy the code
11, UIImageView
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(<#NSObject#>, <#NSObject#>, <#NSObject#>, <#NSObject#>)];
imageView.image=[UIImage imageNamed:<#NSObject#>];
[<#NSObject#> addSubview:imageView];
Copy the code
12, UIButton
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(<#NSObject#>, <#NSObject#>, <#NSObject#>, <#NSObject#>)];
[button setTitle:<#NSObject#> forState:UIControlStateNormal];
[button setTitleColor:<#NSObject#> forState:UIControlStateNormal];
[button addTarget:self action:@selector(<#NSObject#>) forControlEvents:UIControlEventTouchUpInside];
[<#NSObject#> addSubview:button];
Copy the code