1、日期,时间相关
获取当前系统时间戳
(longlong)[[NSDatedate]timeIntervalSince1970]
获取当前系统时间(该获得的系统格式时间已自动添加时区设置)
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
return [dateFormatterstringFromDate:[NSDate date]];
通过特定时间格式获取时间戳
NSDateFormatter *dateFormater = [[NSDateFormatteralloc] init];
[dateFormatersetDateFormat:@"yyyy:MM:DD HH:mm:ss"];
NSDate *date = [dateFormaterdateFromString:timeText];
return (longlong)[date timeIntervalSince1970];
2、图片,颜色
通过特定颜色生成特定尺寸背景图
CGRect rect= frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
if (radius !=0)
{
CGContextBeginPath(context);
CGContextSaveGState(context);
CGContextTranslateCTM (context,CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (context, radius, radius);
float fw =CGRectGetWidth (rect) / radius;
float fh =CGRectGetHeight (rect) / radius;
CGContextMoveToPoint(context, fw, fh/2);
CGContextAddArcToPoint(context, fw, fh, fw/2, fh,1);
CGContextAddArcToPoint(context,0, fh, 0, fh/2,1);
CGContextAddArcToPoint(context,0, 0, fw/2,0, 1);
CGContextAddArcToPoint(context, fw,0, fw, fh/2, 1);
CGContextClosePath(context);
CGContextRestoreGState(context);
CGContextClosePath(context);
CGContextClip(context);
}
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage*theImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
获得特定色值的颜色(宏定义)
#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]
#define UIColorFromARGB(rgbValue, alphaValue) \
[UIColor colorWithRed:((float)((rgbValue &0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:alphaValue]
3、文字相关
文字行距、段距(UILabel Catalogue)
double dHeight =0.0;
NSMutableDictionary *dic = [[NSMutableDictionaryalloc]init];
[dic setObject:self.fontforKey:NSFontAttributeName];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc] init];
[paragraphStyle setLineSpacing:line];
[paragraphStyle setParagraphSpacing:paragraph];
[dic setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
CGRect rect = [self.textboundingRectWithSize:CGSizeMake(self.frame.size.width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOriginattributes:dic context:nil];
dHeight = ceil(rect.size.height);
NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc] initWithString:self.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc] init];
[paragraphStyle setLineSpacing:line];
[paragraphStyle setParagraphSpacing:paragraph];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.textlength])];
[selfsetAttributedText:attributedString];
文字多颜色、字体、大小
NSDictionary *titleDic = [NSDictionarydictionaryWithObjectsAndKeys:[UIFontboldSystemFontOfSize:15.0] ,NSFontAttributeName,UIColorFromRGB(0x333333),NSForegroundColorAttributeName,nil];
NSDictionary *destinationDic = [NSDictionarydictionaryWithObjectsAndKeys:[UIFontsystemFontOfSize:11.0] ,NSFontAttributeName,UIColorFromRGB(0x999999),NSForegroundColorAttributeName,nil];
NSString *string = [NSStringstringWithFormat:@"%@ [%@]" ,@"文字1", @"文字2"];
NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc] initWithString:string];
[attributedString setAttributes:titleDic range:[string rangeOfString:[NSString stringWithFormat:@"%@" ,@"文字1"]]];
[attributedString setAttributes:destinationDic range:[string rangeOfString:[NSString stringWithFormat:@"[%@]",@"文字2"]]];
4、NavigationBar系列
[[UINavigationBarappearance] setBarTintColor:UIColorFromARGB(0x33b5e5,0.85)];//设置Bar背景颜色
[[UINavigationBarappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorwhiteColor], NSForegroundColorAttributeName, [UIFontsystemFontOfSize:18],NSFontAttributeName, nil]];//设置Bar中标题字体颜色
[[UINavigationBarappearance] setTintColor:[UIColorwhiteColor]];//设置系统返回键颜色
UIViewController属性UIRectEdge edgesForExtendedLayout:设置为UIRectEdgeNone以外的值时,View的起点会从顶点开始计算,效果如NavigationBar半透明显示底部效果
[self.navigationController.navigationBarsetTranslucent:YES];
self.navigationController.navigationBar.barStyle =UIBarStyleBlack;
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"背景图.png"]forBarMetrics:UIBarMetricsDefault];
5、GitHub上一些有用的第三方库
Pods Framework
Pods is a development framework for creating, extending, managing, and deploying customized content types in WordPress.
- pod install --verbose --no-repo-update
http://pods.io/
AFNetworking
SDWebImage
jastor
Cordova
MBProgressHUD
JSONKit
MWPhotoBrowser
WCFastCell
解决UITableViewCell 元素较多时,滑动载入屏幕卡屏的问题
WCFastCell is a drop in replacement for UITableViewCell & UICollectionViewCells. It draws subviews' contents (either UILabels or UIImageViews) on a single layer. Thanks to that UITableViews & UICollectionViews scroll more smoothly. It can be especially useful on older devices.