Skip to content

Instantly share code, notes, and snippets.

View yuxiangq's full-sized avatar
🎯
Focusing

Yuxiang yuxiangq

🎯
Focusing
  • ThoughtWorks
  • Chengdu
View GitHub Profile
@yuxiangq
yuxiangq / gist:e1e062116bfc1f948166
Last active August 29, 2015 14:07
p_GetJsonContent
-(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]];
@yuxiangq
yuxiangq / gist:b56b55a42585a8a18d0f
Created November 3, 2014 14:04
给UIImageView添加UITapGestureRecognizer示例
-(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
@yuxiangq
yuxiangq / gist:4dfeebc687b459b629bc
Created November 5, 2014 11:32
UILongPressGestureRecognizer实例
//在这里我需要给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{
@yuxiangq
yuxiangq / gist:ad389e9c32eaec44fc78
Last active August 29, 2015 14:09
UISwipeGestureRecognizer的用法
-(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;
@yuxiangq
yuxiangq / gist:af83a2477e014f5f79b9
Created November 19, 2014 06:31
UIPinchGestureRecognizer的用法
-(void)initUIPinchGestureRecognizer{
UIPinchGestureRecognizer *pinchGestureRecognizer=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector:(pinchHandle:)];
[self.view addGestureRecognizer:pinchGestureRecognizer];
}
-(void)pinchHandle:(UIPinchGestureRecognizer*)sender{
CGFloat scale = sender.scale;//缩放比例
}
@yuxiangq
yuxiangq / gist:de8a69b4873c4b02be32
Created November 19, 2014 09:56
UIRotationGestureRecognizer的使用
UIRotationGestureRecognizer *rotationGestureRecognizer =
[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationHandle:)];
[[self view] addGestureRecognizer:rotationGestureRecognizer];
-(void)rotationHandle:(UIRotationGestureRecognizer*)sender{
CGFloat *rotation = sender.rotation;//旋转弧度
}
@yuxiangq
yuxiangq / gist:93fdc5d139747b410488
Last active August 29, 2015 14:11
UICollectionView的初始化
-(void)initUICollectionView{
//初始化布局方式,这里采用垂直布局。
UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
UICollectionView *collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
[self.view addSubview:collectionView];
}
@yuxiangq
yuxiangq / gist:0c5aa8c4dd9ebc97047a
Created December 14, 2014 13:43
UICollectionViewDataSource的回调方法
//返回有多少个Section,该方法和UITableView的一样
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
//返回每个Section有多少rows
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 1;
}
@yuxiangq
yuxiangq / gist:71a2ac1dabac7b4fa556
Last active August 29, 2015 14:11
NumberField的用法
//...
-(void)viewDidLoad{
[super viewDidLoad];
NumberField *numberField=[[NumberField alloc] initWithFrame:CGRectMake(100, 100, 120, 44)];
numberField.placeholder=@"只能输入数字";
//设置精度,长度为10,小数点位数为4的苏子。
numberField.numeric=CGNumeric(10, 4);
@yuxiangq
yuxiangq / gist:96c5ffeb2ab9d718a33e
Last active August 29, 2015 14:18
customCell的初始化控件方法
-(void)initControls{
_contentLabel=[UILabel new];
_contentLabel.translatesAutoresizingMaskIntoConstraints=NO;
_contentLabel.numberOfLines=0;
_contentLabel.lineBreakMode=NSLineBreakByWordWrapping;
[self.contentView addSubview:_contentLabel];
}