16进制颜色转换
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue &0xFF00) >>8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0]
Application supports iTunes file sharing (bool) 真机测试时在iTunes里查看文件
判断iphone4/5
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)
1.截取字符串
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];//截取下标7之前的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:2];//截取下标2之后的字符串
NSLog(@"截取的值为:%@",string);
2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
NSLog(@"截取的值为:%@",string);
3.分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
创建单例
+ (AccountManager *)sharedManager {
static AccountManager *sharedAccountManagerInstance = nil;
static dispatch_once_t predicate; dispatch_once(&predicate, ^{
sharedAccountManagerInstance = [[self alloc] init];
});
return sharedAccountManagerInstance;
}
圆角
uploadBt = [[UIButton alloc] initWithFrame:CGRectMake(whight/2+0.5, cancelBt.frame.origin.y, whight/2-0.5, 40)];
[uploadBt setTitle:@"上传" forState:UIControlStateNormal];
[uploadBt setBackgroundColor:UIColorFromRGB(0x5078c1)];
[uploadBt addTarget:self action:@selector(upload) forControlEvents:UIControlEventTouchUpInside];
UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, whight/2-0.5, 40)
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(5.0, 5.0)];
CAShapeLayer *maskLayer2 = [CAShapeLayer layer];
maskLayer2.frame = CGRectMake(0, 0, whight/2, 40);
maskLayer2.path = maskPath2.CGPath;
uploadBt.layer.mask = maskLayer2;
时间戳转换
设置时间显示格式:
NSString* timeStr = @"2011-01-26 17:40:50";
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
//设置时区,这个对于时间的处理有时很重要
//例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算.
//例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢?
//他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
NSDate* date = [formatter dateFromString:timeStr]; //------------将字符串按formatter转成nsdate
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSString *nowtimeStr = [formatter stringFromDate:datenow];//----------将nsdate按formatter格式转成nsstring
时间转时间戳的方法:
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //时间戳的值
时间戳转时间的方法
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1296035591];
NSLog(@"1296035591 = %@",confromTimesp);
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
NSLog(@"confromTimespStr = %@",confromTimespStr);
时间戳转时间的方法:
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yyyyMMddHHMMss"];
NSDate *date = [formatter dateFromString:@"1283376197"];
NSLog(@"date1:%@",date);
[formatter release];