一、常用控件
1、UIView懒加载
关键词:GJ_View_Lazy
- (<#UIView#> *)<#yourCode#> {
if (!_<#yourCode#>) {
_<#yourCode#>
_<#yourCode#>
_<#yourCode#>
_<#yourCode#>
_<#yourCode#>
}
return _<#yourCode#>;
}
2、UIView创建
关键词:GJ_View_Create
- (void)create<#yourView#>{
}
3、UILabel - Property & Lazy
关键词:GJ_View_PropertyLabel
@property (nonatomic, strong) UILabel *<#yourCode#>Label;
关键词:GJ_View_LazyLabel
- (UILabel *)<#yourCode#>Label {
if (!_<#yourCode#>) {
_<#yourCode#> = [UILabel createLabelWithFrame:CGRectMake(<#yourCode#>;, <#yourCode#>, <#yourCode#>, <#yourCode#>) text:@"<#yourCode#>"];
_<#yourCode#>.font = [UIFont systemFontOfSize:<#yourCode#>];
_<#yourCode#>.textColor = [UIColor <#yourCode#>];
_<#yourCode#>.backgroundColor = [UIColor <#yourCode#>];
_<#yourCode#>.shadowColor = [UIColor <#yourCode#>];
_<#yourCode#>.shadowOffset = CGSizeMake(<#yourCode#>, <#yourCode#>);
_<#yourCode#>.textAlignment = <#yourCode#>;
_<#yourCode#>.numberOfLines = <#yourCode#>;
_<#yourCode#>.userInteractionEnabled = <#yourCode#>;
_<#yourCode#>.enabled = <#yourCode#>;
_<#yourCode#>.adjustsFontSizeToFitWidth = <#yourCode#>;
}
return _<#yourCode#>;
}
4、Button - Property & Lazy & AddTarget
关键词:GJ_View_PropertyButton
@property (nonatomic, strong) UIButton *<#yourCode#>Button;
关键词:GJ_View_LazyButton
- (UIButton *)<#yourCode#>Button {
if (!_<#yourCode#>) {
_<#yourCode#> = [UIButton buttonWithType:UIButtonTypeCustom];
_<#yourCode#>.frame = CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>);
_<#yourCode#>.backgroundColor = [UIColor <#yourCode#>];
_<#yourCode#>.clipsToBounds = YES;
_<#yourCode#>.layer.cornerRadius = <#yourCode#>;
[_<#yourCode#> setTitle:@"<#yourCode#>" forState:UIControlStateNormal];
[_<#yourCode#> setTitleColor:[UIColor <#yourCode#>] forState:UIControlStateNormal];
[_<#yourCode#> setImage:[UIImage imageNamed:@"<#yourCode#>"] forState:UIControlStateNormal];
[_<#yourCode#> setBackgroundImage:[UIImage imageNamed:@"<#yourCode#>"] forState:UIControlStateNormal];
[_<#yourCode#> addTarget:self action:@selector(<#yourCode#>) forControlEvents:UIControlEventTouchUpInside];
}
return _<#yourCode#>;
}
关键词:GJ_View_ButtonAddTarget
[<#control#> addTarget:self action:@selector(<#controlName#>Click:) forControlEvents:UIControlEventTouchUpInside];
5、Segmented - Property & Lazy
关键词:GJ_View_PropertySegmented
@property (nonatomic, strong) UISegmentedControl *<#yourCode#>SegmentedControl;
关键词:GJ_View_LazySegmented
- (UISegmentedControl *)<#yourCode#>SegmentedControl {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UISegmentedControl alloc]initWithItems:@[@"<#yourCode#>",@"<#yourCode#>"]];
_<#yourCode#>.frame = CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>);
// [_<#yourCode#> insertSegmentWithTitle:@"<#yourCode#>" atIndex:2 animated:YES];
// [_<#yourCode#> removeSegmentAtIndex:2 animated:YES];
[_<#yourCode#> setTitle:@"<#yourCode#>" forSegmentAtIndex:0];
[_<#yourCode#> setWidth:<#yourCode#> forSegmentAtIndex:<#yourCode#>];
[_<#yourCode#> setContentOffset:CGSizeMake(<#yourCode#>, <#yourCode#>) forSegmentAtIndex:<#yourCode#>];
[_<#yourCode#> setEnabled:<#yourCode#> forSegmentAtIndex:<#yourCode#>];
[_<#yourCode#> addTarget:self action:@selector(<#yourCode#>) forControlEvents:UIControlEventValueChanged];
}
return _<#yourCode#>;
}
6、TextField - Property & Lazy
关键词:GJ_View_PropertyTextField
@property (nonatomic, strong) UITextField *<#yourCode#>TextField;
关键词:GJ_View_LazyTextField
- (UITextField *)<#yourCode#>TextField {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UITextField alloc] initWithFrame:CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>)];
_<#yourCode#>.backgroundColor = [UIColor <#yourCode#>];
_<#yourCode#>.font = [UIFont systemFontOfSize:<#yourCode#>];
_<#yourCode#>.textAlignment = <#yourCode#>;
_<#yourCode#>.borderStyle = <#yourCode#>;
_<#yourCode#>.text = @"<#yourCode#>";
_<#yourCode#>.placeholder = @"<#yourCode#>";
_<#yourCode#>.clearsOnBeginEditing = <#yourCode#>;
_<#yourCode#>.clearButtonMode = <#yourCode#>;
_<#yourCode#>.delegate = self;
}
return _<#yourCode#>;
}
7、Slider - Property & Lazy
关键词:GJ_View_PropertySlider
@property (nonatomic, strong) UISlider *<#yourCode#>Slider;
关键词:GJ_View_LazySlider
- (UISlider *)<#yourCode#>Slider {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UISlider alloc] initWithFrame:CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>)];
_<#yourCode#>.minimumValue = <#yourCode#>;
_<#yourCode#>.maximumValue = <#yourCode#>;
_<#yourCode#>.value = <#yourCode#>;
[_<#yourCode#> setThumbImage:[UIImage imageNamed:@"<#yourCode#>"] forState:UIControlStateNormal];
_<#yourCode#>.continuous = <#yourCode#>;
[_<#yourCode#> addTarget:self action:@selector(<#yourCode#>) forControlEvents:UIControlEventValueChanged];
}
return _<#yourCode#>;
}
8、Switch - Property & Lazy
关键词:GJ_View_PropertySwitch
@property (nonatomic, strong) UISwitch *<#yourCode#>Switch;
关键词:GJ_View_LazySwitch
- (UISwitch *)<#yourCode#>Switch {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UISwitch alloc] initWithFrame:CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>)];
_<#yourCode#>.backgroundColor = [UIColor <#yourCode#>];
_<#yourCode#>.onTintColor = [UIColor <#yourCode#>];
_<#yourCode#>.thumbTintColor = [UIColor <#yourCode#>];
[_<#yourCode#> setOn:<#yourCode#> animated:YES];
[_<#yourCode#> addTarget:self action:@selector(<#yourCode#>) forControlEvents:UIControlEventValueChanged];
}
return _<#yourCode#>;
}
9、Activity - Property & Lazy
关键词:GJ_View_PropertyActivity
@property (nonatomic, strong) UIActivityIndicatorView *<#yourCode#>Activity;
关键词:GJ_View_LazyActivity
- (UIActivityIndicatorView *)<#yourCode#>ActivityIndicatorView {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:<#yourCode#>];
_<#yourCode#>.frame = CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>);
_<#yourCode#>.hidesWhenStopped = <#yourCode#>;
[_<#yourCode#> startAnimating];
}
return _<#yourCode#>;
}
10、ProgressView - Property & Lazy
关键词:GJ_View_PropertyProgressView
@property (nonatomic, strong) UIProgressView *<#yourCode#>ProgressView;
关键词:GJ_View_LazyProgressView
- (UIProgressView *)<#yourCode#>ProgressView {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UIProgressView alloc] initWithFrame:CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>)];
_<#yourCode#>.backgroundColor = [UIColor <#yourCode#>];
_<#yourCode#>.progressViewStyle = <#yourCode#>;
_<#yourCode#>.progressTintColor = [UIColor <#yourCode#>];
_<#yourCode#>.trackTintColor = [UIColor <#yourCode#>];
[_<#yourCode#> setProgress:<#yourCode#> animated:YES];
}
return _<#yourCode#>;
}
11、ImageView - Property & Lazy
关键词:GJ_View_PropertyImageView
@property (nonatomic, strong) UIImageView *<#yourCode#>ImageView;
关键词:GJ_View_LazyImageView
- (UIImageView *)<#yourCode#>ImageView {
if (!_<#yourCode#>) {
_<#yourCode#> = [[UIImageView alloc] initWithFrame:CGRectMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>)];
_<#yourCode#>.userInteractionEnabled = <#yourCode#>;
_<#yourCode#>.clipsToBounds = <#yourCode#>;
_<#yourCode#>.layer.cornerRadius = <#yourCode#>;
}
return _<#yourCode#>;
}
12、TableView - Property
关键词:GJ_View_PropertyTableView
@property (nonatomic, strong) UITableView *<#yourCode#>TableView;
13、CollectionView - Property
关键词:GJ_View_PropertyCollectionView
@property (nonatomic, strong) UICollectionView *<#yourCode#>CollectionView;
14、Button Click (Test)
关键词:GJ_View_ButtonEnter
- (UIButton *)clickButton {
if (!_clickButton) {
_clickButton = [UIButton buttonWithType:UIButtonTypeCustom];
_clickButton.center = self.view.center;
_clickButton.bounds = CGRectMake(0, 0, 150, 50);
_clickButton.backgroundColor = [UIColor redColor];
_clickButton.clipsToBounds = YES;
_clickButton.layer.cornerRadius = 5.0f;
[_clickButton setTitle:@"Enter" forState:UIControlStateNormal];
[_clickButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[_clickButton addTarget:self action:@selector(enterButtonClick) forControlEvents:UIControlEventTouchUpInside];
}
return _clickButton;
}
- (void)enterButtonClick {
<#yourViewController#> *controller = [[<#yourViewController#> alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
15、TableView自适应方法版本更新
关键词:GJ_View_TableViewAdjustment
if (@available(iOS 11, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
二、常用API
1、弱引用
关键词:Custom_WeakSelf
__weak typeof(self) weakSelf = self;
2、强引用
关键词:Custom_StrongSelf
__strong typeof(self) strongSelf = weakSelf;
3、通知
关键词:GJ_Notification
/// <#yourCode#>
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#yourCode#>) name:<#yourCode#> object:<#yourCode#>];
-(void)<#yourCode#>:(NSNotification *)notification {
<#yourCode#>
}
4、GJ_Delegate
关键词:GJ_Delegate_If
if (self.delegate && [self.delegate respondsToSelector:@selector(<#selector#>)]) {
[self.delegate <#selector#>];
}
关键词:GJ_Delegate_Creat
@protocol <#DelegateName#> <NSObject>
@required
@optional
- (void)<#delegateMethod#>:(<#Class#> *)<#obj#>;
- (void)<#didBtnLlickCallBack#>(<#Class#> *)<#obj#>;
@end
关键词:GJ_Delegate_TableView
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return <#yourCode#>;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return <#yourCode#>;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return <#yourCode#>;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return <#yourCode#>;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return <#yourCode#>;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
<#yourCode#>
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return <#yourCode#>;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return <#yourCode#>;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"<#yourCode#>";
<#yourCode#> *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[<#yourCode#> alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell drawWithModel:<#yourCode#> indexPatch:indexPath];
return cell;
}
关键词:GJ_Delegate_CollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return <#yourCode#>;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return <#yourCode#>;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"<#yourCode#>";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
<#yourCode#>
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(<#yourCode#>, <#yourCode#>);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(<#yourCode#>, <#yourCode#>, <#yourCode#>, <#yourCode#>);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return <#yourCode#>;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return <#yourCode#>;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
<#yourCode#>
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return <#yourCode#>;
}
5、GJ_Property
关键词:GJ_Property_Strong
@property (nonatomic, strong) <#Class#> *<#obj#>;
关键词:GJ_Property_StrongRead
@property (nonatomic, strong, readonly) <#type#> *<#name#>;
关键词:GJ_Property_Weak
@property (nonatomic, weak) <#Class#> *<#obj#>;
关键词:GJ_Property_WeakRead
@property (nonatomic, weak, readonly) <#type#> *<#name#>;
关键词:GJ_Property_MutableArray
@property (nonatomic, strong) NSMutableArray *<#yourCode#>;
关键词:GJ_Property_NSString
@property (nonatomic, strong) NSString *<#yourCode#>;
关键词:GJ_Property_Class
@property (nonatomic, <#modified#>) <#Class#> <#object#>;
关键词:GJ_Property_Assign
@property (nonatomic, assign) <#type#> <#name#>;
关键词:GJ_Property_AssignRead
@property (nonatomic, assign, readonly) <#type#> <#name#>;
关键词:GJ_Property_Block
@property (nonatomic, copy) <#returnType#> (^<#blockName#>)(<#parameterTypes#>);
关键词:GJ_Property_Copy
@property (nonatomic, copy) <#type#> *<#name#>;
6、NSString拼接
关键词:GJ_String_Format
[NSString stringWithFormat:@"%@", <#needContent#>]
7、GJLog
关键词:GJ_Log_Debug1
GJLogDebug(@"[%@,%@]", <#业务模块#>, <#业务信息描述#>);
关键词:GJ_Log_Debug2
GJLogDebug(@"[%@,%@]:%@", <#业务模块#>, <#业务信息描述#>, <#具体记录参数#>);
关键词:GJ_Log_Error1
GJLogError(@"[%@,%@]", <#业务模块#>, <#业务信息描述#>);
关键词:GJ_Log_Error2
GJLogError(@"[%@,%@]:%@", <#业务模块#>, <#业务信息描述#>, <#具体记录参数#>);
关键词:GJ_Log_Info1
GJLogInfo(@"[%@,%@]", <#业务模块#>, <#业务信息描述#>);
关键词:GJ_Log_Info2
GJLogInfo(@"[%@,%@]:%@", <#业务模块#>, <#业务信息描述#>, <#具体记录参数#>);
关键词:GJ_Log_Verbose1
GJLogVerbose(@"[%@,%@]", <#业务模块#>, <#业务信息描述#>);
关键词:GJ_Log_Verbose2
GJLogVerbose(@"[%@,%@]:%@", <#业务模块#>, <#业务信息描述#>, <#具体记录参数#>);
关键词:GJ_Log_Warn1
GJLogWarn(@"[%@,%@]", <#业务模块#>, <#业务信息描述#>);
关键词:GJ_Log_Warn2
GJLogWarn(@"[%@,%@]:%@", <#业务模块#>, <#业务信息描述#>, <#具体记录参数#>);
关键词:GJ_Log_CallStackSymbols
NSLog(@"Call Stack: %@", [NSThread callStackSymbols]);
8、设置导航标题
关键词:GJ_SetTitle
self.title = @"<#yourCode#>";
[titleV setTitleText:self.title code:nil];
9、弱引用
关键词:GJ_WeakSelf
@weakify(self)
@normalize(self)
10、版本区分
关键词:GJ_Available_If
if (@available(iOS <#12.0#>, *)) {
<#statements#>
}
11、GJ_Constant
关键词:GJ_Extern_Const1
FOUNDATION_EXPORT <#type#> *const <#name#>;
关键词:GJ_Extern_Const2
FOUNDATION_EXPORT const <#type#> <#name#>;
关键词:Custom_Extern_Const1
extern <#type#> *const <#name#>;
关键词:Custom_Extern_Const2
extern const <#type#> <#name#>;
关键词:GJ_Const1
<#type#> *const <#name#> = <#value#>;
关键词:GJ_Const2
const <#type#> <#name#> = <#value#>;
关键词:GJ_Static_Const1
static <#type#> *const k<#name#> = <#value#>;
关键词:GJ_Static_Const2
static <#type#> const k<#Name#> = <#value#>;
三、Annotation (代码备注)
1、分段
关键词:GJ_Code_Mark
#pragma mark -
2、代码添加记录
关键词:GJ_Code_Add
/**
Add by <#yourname#> : <#needContent#>
Time: <#Y:M:D#>
Version: <#v*.*.*#>
*/
3、代码修改记录
关键词:GJ_Code_Change
/**
Change by <#yourname#> : <#needContent#>
Time: <#addTime#>
Version: <#addVersion#>
*/
4、代码删除记录
关键词:GJ_Code_Del
/**
Del by <#yourname#> : <#needContent#>
Time: <#addTime#>
Version: <#addVersion#>
*/
5、方法描述
关键词:GJ_Code_Describe
/**
* @brief <#方法描述#>
*
* @param <#参数描述1#>
*
* @param <#参数描述2#>
*
*/
6、方法生效版本
关键词:GJ_Method_Availability
__attribute__((availability(ios,introduced=<#beginVersion#>,deprecated=<#endversion#>,message="用 <#-newMethod#>: 这个方法替代 ")))
7、方法替换
关键词:GJ_Method_Instead
DEPRECATED_MSG_ATTRIBUTE("use <#message#>: instead")
8、方法创建(无参数)
关键词:GJ_Method_Creat
- (void)<#yourCode#> {
<#yourCode#>
}
9、方法创建(有参数)
关键词:GJ_Method_CreatWith
- (void)<#method name#>:(<#argv type#>)<#argv#> {
<#code#>
}
四、常用代码块
1、创建一个串行队列
关键词:GJ_GCD_CreateSerialQueue
dispatch_queue_t <#yourCode#>Queue = dispatch_queue_create("com.gtja.app.<#yourCode#>", DISPATCH_QUEUE_SERIAL);
dispatch_async(<#yourCode#>Queue, ^{
<#yourCode#>
dispatch_async(dispatch_get_main_queue(), ^{
<#yourCode#>
});
});
2、获取全局队列
关键词:GJ_GCD_CreateGlobalQueue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {
<#yourCode#>
dispatch_async(dispatch_get_main_queue(), ^{
<#yourCode#>
});
});
3、引入头文件
关键词:GJ_Header_Import
// ViewControllers
// Utils
// Models
// Views
4、self调用方法
关键词:GJ_Setup_Didload
[self setupData];
[self setupView];
[self configLayout];
[self registerNotification];
#pragma mark - Request
- (void)setupData {
}
#pragma mark - SetupView
- (void)setupView {
}
- (void)configLayout {
}
#pragma mark - Notification
- (void)registerNotification {
}
关键词:GJ_SetupData
[self setupData];
#pragma mark - Request
- (void)setupData {
}
关键词:GJ_SetupView
[self setupView];
[self configLayout];
#pragma mark - SetupView
- (void)setupView {
}
- (void)configLayout {
}
关键词:GJ_Setup_Notification
[self registerNotification];
#pragma mark - Notification
- (void)registerNotification {
}
5、枚举
关键词:GJ_Enum_Creat
typedef NS_ENUM(NSUInteger, <#yourCode#>) {
<#value0#> = 0,
<#value1#>
};
6、选项
关键词:GJ_Option_Creat
typedef NS_OPTIONS(NSUInteger, <#yourCode#>) {
<#value0#> = 0,
<#value1#>
};
7、生命周期
关键词:GJ_LifeCycle
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)loadUIData {
[super loadUIData];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)dealloc {
}
#pragma mark - Override
#pragma mark - SetupView
#pragma mark - Request
#pragma mark - Response
#pragma mark - UITableViewDataSource & UITableViewDelegate
#pragma mark - CustomDelegate
#pragma mark - Event Action
#pragma mark - Custom Method
#pragma mark - Notification
#pragma mark - Navigation Push Acton
#pragma mark - Setter & Getter
#pragma mark - LazyInit
#pragma mark - MemoryWarning
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
8、GJ_NSUserDefaults
关键词:GJ_NSUserDefaults_Set
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:<#object#> forKey:<#key#>];
[defaults synchronize];
关键词:GJ_NSUserDefaults_Get
[[NSUserDefaults standardUserDefaults] objectForKey:<#key#>];
关键词:GJ_NSUserDefaults_Remove
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:<#key#>];
[defaults synchronize];
9、单例
关键词:GJ_SharedInstance
+ (<#_type_#> *)sharedInstance {
static <#_type_#> *_instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[super allocWithZone:nil] init];
});
return _instance;
}
10、手势
关键词:GJ_Gesture_Tap
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGestureRecognizer:)];
tap.numberOfTapsRequired = <#tapNum#>;
tap.numberOfTouchesRequired = <#touchNum#>;
[<#addView#> addGestureRecognizer:tap];
- (void)handleTapGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer {
}
关键词:GJ_Gesture_Swipe
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(UISwipeGestureRecognizer:)];
swipe.numberOfTouchesRequired = <#touchNum#>;
swipe.direction = <#direction#>;
[<#addView#> addGestureRecognizer:swipe];
- (void)handleSwipeGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer {
}
关键词:GJ_Gesture_LongPress
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPressGestureRecognizer:)];
longPress.minimumPressDuration = <#longPressTime#>;
[<#addView#> addGestureRecognizer:longPress];
- (void)handleLongPressGestureRecognizer:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
}
}
关键词:GJ_Gesture_Pan
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)];
[<#addView#> addGestureRecognizer:pan];
- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer {
if(gestureRecognizer.state == UIGestureRecognizerStateBegan) {
// 开始拖动
}else if(gestureRecognizer.state == UIGestureRecognizerStateChanged) {
// 正在拖动,获取拖动坐标
CGPoint transP = [gestureRecognizer translationInView:<#superView#>];
}else if(gestureRecognizer.state == UIGestureRecognizerStateEnded) {
//结束拖动
}
}
11、耗时计算
关键词:GJ_Time_Consuming
CFTimeInterval startTime = CACurrentMediaTime();
<#code here#>
CFTimeInterval endTime = CACurrentMediaTime();
CFTimeInterval consumingTime = endTime - startTime;
NSLog(@"耗时:%@", @(consumingTime));
网友评论