Skip to content

Instantly share code, notes, and snippets.

@JeOam
JeOam / gist:71d11f3d09b157af3681
Created June 11, 2014 05:23
点击任意位置,隐藏键盘输入框
#pragma mark - touchMethod
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
[self allEditActionsResignFirstResponder];
}
- (void)allEditActionsResignFirstResponder{
[[self.view viewWithTag:Tag_UsernameTextField] resignFirstResponder];
@JeOam
JeOam / alertView.m
Last active August 29, 2015 14:02
alertView UIAlertView template
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Title"
message:@"message"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alertView show];
#pragma marks -- UIAlertViewDelegate
//根据被点击按钮的索引处理点击事件
@JeOam
JeOam / UI.md
Last active August 29, 2015 14:02
Sizes of iPhone UI Elements
@JeOam
JeOam / isValidateEmail.m
Created June 11, 2014 10:28
检验字符串是否为有效的邮箱
- (BOOL)isValidateEmail:(NSString *)email {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
@JeOam
JeOam / Compile.m
Last active August 29, 2015 14:02
Compile Option
#warning - 手动创建 warning
#pragma mark - 类似类方法导航的标识
#pragma mark - tableView delegate
@JeOam
JeOam / cacheImage.md
Last active August 29, 2015 14:02
Get Image from URL and Save it to disk/Read it back and Upload it
// 根据 url 获取图片
UIImage *imageToSave = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dic objectForKey:@"userPic"]]]];

// 获取 Documents 文件夹目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

// 转换成 NSData 格式
NSData * binaryImageData = UIImagePNGRepresentation(imageToSave);
@JeOam
JeOam / screenImage.m
Last active August 29, 2015 14:02
Get Screen Shot
//截取屏幕图片
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//以png格式返回指定图片的数据
NSData *screenImageData = UIImagePNGRepresentation(screenImage);
@JeOam
JeOam / git.md
Last active August 29, 2015 14:02
常用 Git 操作
  • 转到目标(空)文件夹,然后 clone 仓库:
$ git clone Git地址
  • 验证是否 clone 成功:
$ ls
@JeOam
JeOam / Delegates.md
Last active August 29, 2015 14:02
To pass data back from ViewControllerB to ViewControllerA using Protocols and Delegates
  1. In ViewControllerB.h, below the #import, but above @interface you specify the protocol.
@protocol adTapGestureCapturedDelegate <NSObject>
-(void)adTapGestureCaptured:(UITapGestureRecognizer *)gesture;
@end

2.next still in the ViewControllerB.h you need to setup a delegate property and synthesize in ViewControllerB.m.

@property (weak, nonatomic) id<adTapGestureCapturedDelegate> delegate;
@JeOam
JeOam / UITextView.md
Last active August 29, 2015 14:02
UITextView 模板

Just like UITextField, but there are some differences listed below.