工具others

来源:互联网 发布:帝国cms 附件存放目录 编辑:程序博客网 时间:2024/06/11 01:05
+ (void)setExtraCellLineHidden:(UITableView *)tableView{    UIView *view = [[UIView alloc] init];    view.backgroundColor = [UIColor clearColor];    [tableView setTableFooterView:view];}+ (void)setSettingTableViewStyle:(UITableView *)tableView{    CGRect frame = tableView.bounds;    frame.origin.y = -frame.size.height;    UIView *boundsView = [[UIView alloc] initWithFrame:frame];    CGFloat value = 242.0 / 255;    boundsView.backgroundColor = [UIColor colorWithRed:value green:value blue:value alpha:1];    [tableView addSubview:boundsView];    if (!iOS7) {        tableView.backgroundView = nil;    }}+ (UIImageView *)loadImageViewWithURL:(NSString *)url imageViewFrame:(CGRect)frame superView:(UIView *)view{    UIImageView *imageView = [self loadImageViewWithURL:url imageViewFrame:frame superView:view contentMode:UIViewContentModeScaleAspectFill];    return imageView;}+ (UIImageView *)loadImageViewWithURL:(NSString *)url imageViewFrame:(CGRect)frame superView:(UIView *)view contentMode:(UIViewContentMode)contentMode{    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];    imageView.contentMode = contentMode;    imageView.clipsToBounds = YES;        [self setImageWithURL:url imageView:imageView];        [view addSubview:imageView];    return imageView;}+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView contentMode:(UIViewContentMode)contentMode{    imageView.contentMode = contentMode;    imageView.clipsToBounds = YES;        [self setImageWithURL:url imageView:imageView];}+ (void)setImageWithURL:(NSString *)url imageView:(UIImageView *)imageView{    NSString *imageURL;    if (url && url.length > 0) {        // 设置尺寸        NSArray *sizeArray = @[@64, @128, @256, @512, @768, @1024];        NSUInteger realWidth = (NSUInteger)CGRectGetWidth(imageView.frame) * 2;        NSUInteger fitWidth = 0;        for (NSNumber *number in sizeArray) {            NSUInteger width = [number unsignedIntegerValue];            if (width >= realWidth) {                fitWidth = width;                break;            }        }                NSString *fileName = [url stringByDeletingPathExtension];        NSString *fileExtension = [url pathExtension];        if (fitWidth == 0) {            imageURL = [NSString stringWithFormat:@"%@%@.%@", kImageURL, fileName, fileExtension];        } else {            imageURL = [NSString stringWithFormat:@"%@%@_%i.%@", kImageURL, fileName, fitWidth, fileExtension];        }    }    NSLog(@"%@", imageURL);    [imageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder"]];}/** *  修改App颜色 * *  @param color 颜色 */+ (void)setAppColor:(UIColor *)color{    [Singleton shareInstance].backgroundColor = color;        [[AppDelegate shareDelegate] changeAppColor];}/** *  获取App颜色 * *  @return App颜色 */+ (UIColor *)getAppColor{    UIColor *color;    if ([AppDelegate shareDelegate].frontNavigationController) { // 从数据库读取        color = [StyleColorModel getCurrentColor];    } else { // 未登录则用默认的        color = [UIColor colorWithRed:0.2118 green:0.3294 blue:0.6196 alpha:1.0000];    }        return color;}/** *  用颜色创建图片 * *  @param color 图片颜色 *  @param size  图片尺寸 * *  @return 图片 */+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size{    //Create a context of the appropriate size    UIGraphicsBeginImageContext(size);    CGContextRef currentContext = UIGraphicsGetCurrentContext();        //Build a rect of appropriate size at origin 0,0    CGRect fillRect = CGRectMake(0,0,size.width,size.height);        //Set the fill color    CGContextSetFillColorWithColor(currentContext, color.CGColor);        //Fill the color    CGContextFillRect(currentContext, fillRect);        //Snap the picture and close the context    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();        return image;}
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)#define kScreenWidth CGRectGetWidth([UIScreen mainScreen].bounds)#define kScreenHeight CGRectGetHeight([UIScreen mainScreen].bounds)#define iOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0


0 0
原创粉丝点击