1.常用的代理方法套路
@class UserModel;
@protocol UserOperationDelegate
// 所有的点击都绑在这个代理方法
-(void)IconImageViewTapped:(int)userId ;
-(void)LikeButtonClicked:(UIButton *)button;
@end
@interface UserOperationView : UIView
@property (nonatomic , strong) iddelegate;
@property (nonatomic, strong) UserModel *userModel;
@end
2.常用的Block定义套路
3.常用的枚举定义套路
4.常用的主视图窗口套路
ViewController* vc = [[ViewController alloc]init];
UINavigationController * nav =[[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
5.常用的一些宏定义
#define ScreenBounds [[UIScreen mainScreen]bounds]
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#import
#import
#define MainColor [UIColor colorWithRed:14/255.0 green:84/255.0 blue:113/255.0 alpha:1.0]
#define BackColor [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1]
// 系统版本
#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
// 邮箱注册
#define RegisterWithEmailAndPwd(tel,pwd) [NSString stringWithFormat:@"http://192.168.1.108:8080/batManage/User/register.action?user.userEmail=%@&user.userPwd=%@",tel,pwd];
6.常用的添加手势方法
//单击,双击,捏合,长按
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer* twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
doubleTap.numberOfTapsRequired = 2;
twoFingerTap.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:singleTap];
[self.view addGestureRecognizer:doubleTap];
[self.view addGestureRecognizer:twoFingerTap];
[self.view addGestureRecognizer:longPress];
[singleTap requireGestureRecognizerToFail:doubleTap];
-(void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer{}
-(void)handleDoubleTap:(UITapGestureRecognizer *)gestureRecognizer{}
-(void)handleTwoFingerTap:(UITapGestureRecognizer *)gestureRecongnizer{}
-(void)longPress:(UIGestureRecognizer*)gestureRecongnizer{}
7.常用的延迟操作
double delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//do SomeThing...
});
8.常用的路径设置
$(SRCROOT)/TestDemo/PrefixHeader.pch
9.区分Label不同区域的颜色方法
UILabel * label = [[UILabel alloc]initWithFrame:CGRectZero];
NSString* str1=@" 联系邮箱";
NSString* str2=@"(选填)";
NSMutableAttributedString *mutableText = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",str1,str2]];
NSRange rangetext = [[mutableText string] rangeOfString:str2];
[mutableText addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:rangetext];
label.attributedText=mutableText;
label.font=[UIFont systemFontOfSize:18];
10.无扩展情况下的快速创建方法
-(void)createLabel
{
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-140)/2, 390, 140, 21)];
label.text=@"暂不支持第三方账号登录";
label.textColor=[UIColor grayColor];
label.textAlignment=NSTextAlignmentCenter;
label.font=[UIFont systemFontOfSize:14];
[self.view addSubview:label];
}
-(UITextField *)createTextFielfFrame:(CGRect)frame font:(UIFont *)font placeholder:(NSString *)placeholder
{
UITextField *textField=[[UITextField alloc]initWithFrame:frame];
textField.font=font;
textField.textColor=[UIColor grayColor];
textField.borderStyle=UITextBorderStyleNone;
textField.placeholder=placeholder;
return textField;
}
-(UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName color:(UIColor *)color
{
UIImageView *imageView=[[UIImageView alloc]initWithFrame:frame];
if (imageName)
{
imageView.image=[UIImage imageNamed:imageName];
}
if (color)
{
imageView.backgroundColor=color;
}
return imageView;
}
11.字符串的编码,解码
+(NSString*)encodeString:(NSString*)unencodedString{
// CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
// CharactersToLeaveUnescaped = @"[].";
NSString *encodedString = (NSString *)
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedString;
}
//URLDEcode
-(NSString *)decodeString:(NSString*)encodedString
{
//NSString *decodedString = [encodedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];
NSString *decodedString = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
(__bridge CFStringRef)encodedString,
CFSTR(""),
CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
return decodedString;
}
12.保持TableVIewCell的某一个单元格选中状态
1.[_tableView selectRowAtIndexPath:self.selectIndex animated:YES scrollPosition:UITableViewScrollPositionNone]//(TableView设置)
2.
self.selectionStyle=UITableViewCellSelectionStyleGray;//()
13.显示手机的网络菊花
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];