123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- //
- // 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)noThing{}
- -(void)configNavigationBarHideLeft
- {
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(noThing)];
- [backBbi setTintColor:[UIColor clearColor]];
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- - (void)navPushHideTabbarToVC:(UIViewController*)vc {
- //判断是否是homebase的子视图控制器(它的子视图控制器直接设置self.hidesBottomBarWhenPushed = YES;会无效)
- dispatch_async(dispatch_get_main_queue(), ^{
- self.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- if (!self.navigationController.tabBarController.tabBar.isHidden) {
- self.hidesBottomBarWhenPushed = NO;
- }
- });
- }
- -(void)configNavigationBar{
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackByNavigation)];
- [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:@"backIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackFirstVCByNavigation)];
- [self.navigationItem setLeftBarButtonItem:backBbi];
- self.navigationController.navigationBar.translucent = NO;
- }
- -(void)goBackFirstVCByNavigation{
-
- [self.view endEditing:1];
- [self.navigationController popViewControllerAnimated:YES];
- // UIViewController *vc = [self.navigationController.viewControllers firstObject];
- // [self.navigationController popToViewController:vc animated:YES];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- }
- -(void)configNavigationBarDismissNav
- {
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNav)];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- -(void)configNavigationBarPopRoot{
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(gotoRoot)];
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- -(void)gotoRoot{
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- -(void)dismissNav
- {
- [self.view endEditing:YES];
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- }
- @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 CornerRadius:(NSInteger)cornerRadius {
- [self.layer setBorderWidth:width];
- [self.layer setBorderColor:color.CGColor];
- [self.layer setMasksToBounds:YES];
- [self.layer setCornerRadius:cornerRadius];
- }
- -(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:RQlineColor];
- }
- -(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];
- }
|