// // UIFormatter.m // test11 // // Created by apple on 15/11/13. // Copyright (c) 2016年 JCZ. All rights reserved. // #import "UIFormatter.h" @implementation UIFormatter @end CGRect SGRectMake(CGFloat x, CGFloat y,CGFloat width,CGFloat height){ CGFloat rateX = kSize.width / 320; CGFloat rateY = kSize.height / 480; // rateY = rateX; return CGRectMake(x * rateX, y * rateY, width * rateX, height * rateY); } CGRect SGRectMakeCH(CGFloat x, CGFloat y,CGFloat width,CGFloat height){ CGFloat rateX = kSize.width / 320; CGFloat rateY = kSize.height / 480; return CGRectMake(x * rateX, y * rateY, width * rateX, height * 1); } CGRect SGRectMakeCY(CGFloat x, CGFloat y,CGFloat width,CGFloat height){ CGFloat rateX = kSize.width / 320; CGFloat rateY = kSize.height / 480; return CGRectMake(x * rateX, y * 1, width * rateX, height * rateY); } CGRect SGRectMakeCYH(CGFloat x, CGFloat y,CGFloat width,CGFloat height){ CGFloat rateX = kSize.width / 320; // CGFloat rateY = kSize.height / 480; return CGRectMake(x * rateX, y * 1, width * rateX, height * 1); } CGSize SGSizeMake(CGFloat width,CGFloat height){ CGFloat rateX = kSize.width / 320; CGFloat rateY = kSize.height / 480; return CGSizeMake(width * rateX, height * rateY); } CGFloat SGFloat(CGFloat k) { return k * kSize.height / 480; } //@implementation UIViewController(Navigation) // //-(void)configNavigationBarHideLeft //{ // UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(noThing)]; // [backBbi setTintColor:[UIColor clearColor]]; // [self.navigationItem setLeftBarButtonItem:backBbi]; //} // //-(void)navPushHideTabbarToVC:(UIViewController*)vc //{ // [self.navigationController pushViewController:vc animated:YES]; //} // //-(void)configNavigationBar{ // UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackByNavigation)]; // [backBbi setTintColor:defGreen]; // [self.navigationItem setLeftBarButtonItem:backBbi]; // self.navigationController.navigationBar.translucent = NO; //} // //-(void)goBackByNavigation{ // // [self.view endEditing:1]; // [self.navigationController popViewControllerAnimated:YES]; //} // ////回到导航控制器的首视图 //-(void)configNavigationBarFirstVC{ // UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackFirstVCByNavigation)]; // [backBbi setTintColor:defGreen]; // [self.navigationItem setLeftBarButtonItem:backBbi]; // self.navigationController.navigationBar.translucent = NO; //} // //-(void)goBackFirstVCByNavigation{ // // [self.view endEditing:1]; // UIViewController *vc = [self.navigationController.viewControllers firstObject]; // [self.navigationController popToViewController:vc animated:YES]; // //[self.navigationController popToRootViewControllerAnimated:YES]; //} // //-(void)configNavigationBarPopRoot{ // UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(gotoRoot)]; // [backBbi setTintColor:defGreen]; // [self.navigationItem setLeftBarButtonItem:backBbi]; //} // //-(void)gotoRoot{ // [self.navigationController popToRootViewControllerAnimated:YES]; //} // //@end //生成带颜色的图片 可以用作按钮点击变色 @implementation UIImage (Extension) + (UIImage *)imageWithColor:(UIColor *)color { CGFloat imageW = 3; CGFloat imageH = 3; // 1.开启基于位图的图形上下文 UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageW, imageH), NO, 0.0); // 2.画一个color颜色的矩形框 [color set]; UIRectFill(CGRectMake(0, 0, imageW, imageH)); // 3.拿到图片 UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); // 4.关闭上下文 UIGraphicsEndImageContext(); return image; } @end @implementation UIImage (scale) /** * 修改图片的大小 */ -(UIImage*)originImageScaleToSize:(CGSize)size { UIGraphicsBeginImageContext(size); //size 为CGSize类型,即你所需要的图片尺寸 [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; //返回的就是已经改变的图片 } @end @implementation UIImage(tint) // Tint: Color -(UIImage*)tint:(UIColor*)color { return [self rt_tintedImageWithColor:color level:1.0f]; } // Tint: Color + level -(UIImage*)rt_tintedImageWithColor:(UIColor*)color level:(CGFloat)level { CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); return [self rt_tintedImageWithColor:color rect:rect level:level]; } // Tint: Color + Rect -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect { return [self rt_tintedImageWithColor:color rect:rect level:1.0f]; } // Tint: Color + Rect + level -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect level:(CGFloat)level { CGRect imageRect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, self.scale); CGContextRef ctx = UIGraphicsGetCurrentContext(); [self drawInRect:imageRect]; CGContextSetFillColorWithColor(ctx, [color CGColor]); CGContextSetAlpha(ctx, level); CGContextSetBlendMode(ctx, kCGBlendModeSourceAtop); CGContextFillRect(ctx, rect); CGImageRef imageRef = CGBitmapContextCreateImage(ctx); UIImage *darkImage = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; CGImageRelease(imageRef); UIGraphicsEndImageContext(); return darkImage; } @end @implementation UIView(formatter) -(void)setRound { self.layer.masksToBounds = YES; self.layer.cornerRadius = self.width/2.0; } -(void)setBoardWid:(CGFloat)width Color:(UIColor*)color { [self.layer setBorderWidth:width]; [self.layer setBorderColor:color.CGColor]; [self.layer setMasksToBounds:YES]; [self.layer setCornerRadius:6]; } -(void)addViewWithRect:(CGRect)re Color:(UIColor*)color { UIView *v = [[UIView alloc] initWithFrame:re]; [v setBackgroundColor:color]; [self.superview addSubview:v]; } -(void)addViewWithRect:(CGRect)re { [self addViewWithRect:re Color:lineColor]; } -(void)addSelfViewWithRect:(CGRect)re Color:(UIColor*)color { UIView *v = [[UIView alloc] initWithFrame:re]; [v setBackgroundColor:color]; [self addSubview:v]; } -(void)scale:(CGFloat)rate { self.transform = CGAffineTransformScale(CGAffineTransformIdentity, rate,rate); } @end @implementation UILabel(formatter) -(void)setFont:(CGFloat)font TextColor:(UIColor*)color { [self setFont:[UIFont scaleSize:font]]; [self setTextColor:color]; } -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color { [self setText:text]; [self setFont:[UIFont scaleSize:font]]; [self setTextColor:color]; } -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align { [self setText:text Font:font TextColor:color]; [self setTextAlignment:align]; } @end @implementation UIFont(scale) +(id)scaleSize:(CGFloat)font { return [UIFont systemFontOfSize:font*kSize.width / 414.0]; } @end UIImage* randomPortrait() { NSString* str = [NSString stringWithFormat:@"portrait%d.png",arc4random()%10 + 1]; return [UIImage imageNamed:str]; } UIColor * randomColor() { UIColor *color = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0]; return color; } void setRandomColor(UIView* vi) { UIColor *color = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0]; [vi setBackgroundColor:color]; }