This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)p_GetJsonContent{ | |
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; | |
NSURL *URL = [NSURL URLWithString:@"https://raw.githubusercontent.com/lovekarri/exercise/master/content.json"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:URL]; | |
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { | |
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; | |
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)initUIImageView{ | |
UIImageView imageView = [[UIImageView alloc] init]; | |
imageView.userInteractionEnabled = YES; | |
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)] | |
[imageView addGestureRecognizer:tapGestureRecognizer]; | |
} | |
-(void)tapImageView:(UITapGestureRecognizer*)sender{ | |
//doSomething |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//在这里我需要给UITableViewCell添加长按手势,非重点代码我将省略 | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ | |
//... | |
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:@selector(longPressDoSomething:)]; | |
[cell addGestureRecognizer:longPressGestureRecognizer]; | |
//... | |
return cell; | |
} | |
-(void)longPressDoSomething:(UILongPressGestureRecognizer*)sender{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)initSwipeGestureRecognizer{ | |
UISwipeGestureRecognizer *swipeGestureRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; | |
[self.view addGestureRecognizer:swipeGestureRecognizer]; | |
} | |
-(void)swipe:(UISwipeGestureRecognizer*)sender{ | |
switch(sender.direction){ | |
case UISwipeGestureRecognizerDirectionRight: | |
{ | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)initUIPinchGestureRecognizer{ | |
UIPinchGestureRecognizer *pinchGestureRecognizer=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector:(pinchHandle:)]; | |
[self.view addGestureRecognizer:pinchGestureRecognizer]; | |
} | |
-(void)pinchHandle:(UIPinchGestureRecognizer*)sender{ | |
CGFloat scale = sender.scale;//缩放比例 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIRotationGestureRecognizer *rotationGestureRecognizer = | |
[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationHandle:)]; | |
[[self view] addGestureRecognizer:rotationGestureRecognizer]; | |
-(void)rotationHandle:(UIRotationGestureRecognizer*)sender{ | |
CGFloat *rotation = sender.rotation;//旋转弧度 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)initUICollectionView{ | |
//初始化布局方式,这里采用垂直布局。 | |
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init]; | |
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; | |
UICollectionView *collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; | |
[self.view addSubview:collectionView]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//返回有多少个Section,该方法和UITableView的一样 | |
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ | |
return 1; | |
} | |
//返回每个Section有多少rows | |
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
-(void)viewDidLoad{ | |
[super viewDidLoad]; | |
NumberField *numberField=[[NumberField alloc] initWithFrame:CGRectMake(100, 100, 120, 44)]; | |
numberField.placeholder=@"只能输入数字"; | |
//设置精度,长度为10,小数点位数为4的苏子。 | |
numberField.numeric=CGNumeric(10, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)initControls{ | |
_contentLabel=[UILabel new]; | |
_contentLabel.translatesAutoresizingMaskIntoConstraints=NO; | |
_contentLabel.numberOfLines=0; | |
_contentLabel.lineBreakMode=NSLineBreakByWordWrapping; | |
[self.contentView addSubview:_contentLabel]; | |
} |
OlderNewer