// // UtilsTools.m // smartRhino // // Created by armin on 2019/11/1. // Copyright © 2019 tederen. All rights reserved. // #import "UtilsTools.h" @implementation UtilsTools #pragma mark - UIModalPresentationStyle 显示方式 + (UIModalPresentationStyle)modalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle { UIModalPresentationStyle returnModalPresentationStyle; if ((modalPresentationStyle == UIModalPresentationFullScreen/*0*/) || (modalPresentationStyle == UIModalPresentationCurrentContext/*3*/) || (modalPresentationStyle == UIModalPresentationCustom/*4*/) || (modalPresentationStyle == UIModalPresentationOverFullScreen/*5*/) || (modalPresentationStyle == UIModalPresentationOverCurrentContext/*6*/)) { returnModalPresentationStyle = modalPresentationStyle; }else if((modalPresentationStyle == UIModalPresentationPageSheet/*1*/) || (modalPresentationStyle == UIModalPresentationFormSheet/*2*/) || (modalPresentationStyle == UIModalPresentationPopover/*7*/)) { returnModalPresentationStyle = UIModalPresentationFullScreen; }else{ //UIModalPresentationBlurOverFullScreen/*8*/ //UIModalPresentationNone/*-1*/ //UIModalPresentationAutomatic/*-2*/ returnModalPresentationStyle = UIModalPresentationFullScreen; } return returnModalPresentationStyle; } +(UIWindow*)getWindow { UIWindow* win = nil; //[UIApplication sharedApplication].keyWindow; for (id item in [UIApplication sharedApplication].windows) { if([item class] == [UIWindow class]) { if(!((UIWindow*)item).hidden) { win = item; break; } } } return win; } + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size { CGRect rect = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } + (UIImage*) imageWithColor:(UIColor*)color andHeight:(CGFloat)height { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } //计算聊天消息的高 不是公用 + (CGFloat)calculationHeightWithContent:(NSString *)content{ CGFloat oneLineMaxW = SCREEN_WIDTH - (81+87); CGSize size = [content sizeWithFont:[UIFont systemFontOfSize:16] byWidth:oneLineMaxW textLineSpacing:5]; if(size.height <= 40){ return 40 + 15; }else{ return size.height + 15 + 14*2; } } //计算聊天消息的宽 不是公用 + (CGFloat)calculationWidthWithContent:(NSString *)content{ CGFloat oneLineMaxW = SCREEN_WIDTH - (81+87); UILabel *tempLabel = [[UILabel alloc] init]; tempLabel.frame = CGRectMake(0, 0, oneLineMaxW, 1); tempLabel.text = content; [tempLabel sizeToFit]; if(tempLabel.width > oneLineMaxW){ return SCREEN_WIDTH - 97 - oneLineMaxW; }else{ return SCREEN_WIDTH - 97 - tempLabel.width; } } @end