保留两位小数运算
float xxx = floorf(([middleMutableArray[0] floatValue] * 100)/100)/caloriePlanValue ;
修改状态栏颜色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
计时器timer类一定要记得[timer invalidate];
timer = nil; 否则影响ViewController的释放
//无法获取OpenGL的数据
//屏幕截屏保存到沙盒self.view.frame.size
//待添加一个按钮,保存当前屏幕图片到相册
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height/2)); //currentView 当前的view
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *screenShotPNG = UIImagePNGRepresentation(viewImage);
NSError *error = nil;
[screenShotPNG writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"share.png"] options:NSAtomicWrite error:&error];
截图
UIView * snapView = [self.view snapshotViewAfterScreenUpdates:NO];
目前使用两张图合并的方法
-(void)saveImageFormView {
//保存当前屏幕图片到相册
//
UIImage * mapImage = [mapView takeSnapshot];
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContextWithOptions(screenWindow.frame.size, NO, 0);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum([self addImage:image toImage:mapImage], nil, nil, nil); //保存到相册中
}
//拼接图片
- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {
UIGraphicsBeginImageContextWithOptions(image1.size, NO, 0);
// Draw image1
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
// Draw image2
[image2 drawInRect:CGRectMake(0, self.mapContentView.frame.origin.y+64, image2.size.width, image2.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
Images.xcassets中的素材
(1)只支持png格式的图片
(2) 图片只支持[UIImage imageNamed]的方式实例化,但是不能从Bundle中加载
(3) 在编译时,Images.xcassets中的所有文件会被打包为Assets.car的文件
时间戳转换成NSdate
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[time intValue]];
设置NSdate 格式
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"HH:MM"];
将NSdate转换成formatter格式的String
[formatter stringFromDate:confromTimesp];
制作覆盖全屏的高斯模糊背景
通过使用UIWindow来使该View位于最上层
截取当前屏幕图片模糊化后设置为UIWindow的背景
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContextWithOptions(screenWindow.frame.size, NO, 0);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage * blurimage = [UIImage imageByApplyingLightEffectToImage:image];
blurWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
blurWindow.windowLevel = UIWindowLevelAlert;
blurWindow.backgroundColor = [UIColor colorWithPatternImage:blurimage];
blurWindow.hidden = NO;
杂项
NSString * string = [dictionary objectForKey:@"status"];
if ([string isEqualToString:@"success"]) {
handler(YES,string,nil);
}else if ([string isEqualToString:@"failure"])
handler(NO,string,[NSError errorWithDomain:[dictionary objectForKey:@"error"] code:-1 userInfo:nil]);
NSArray *array = (NSArray *)responseObject;
if (array) {
NSMutableArray *result = [[NSMutableArray alloc] init];
for (NSDictionary *object in array) {
[result addObject:[self createFriendsArticlesCommentsModel:object]];
}
handler(YES,result,nil);
} else {
handler(NO,nil,[NSError errorWithDomain:@"error" code:-1 userInfo:nil]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
handler(NO,nil, error);}];
填充一个图片为View的背景
self.texttableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"FriendinTableViewBackground.png"]];