UtilsTools.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // UtilsTools.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/1.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "UtilsTools.h"
  9. @implementation UtilsTools
  10. #pragma mark - UIModalPresentationStyle 显示方式
  11. + (UIModalPresentationStyle)modalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle {
  12. UIModalPresentationStyle returnModalPresentationStyle;
  13. if ((modalPresentationStyle == UIModalPresentationFullScreen/*0*/) ||
  14. (modalPresentationStyle == UIModalPresentationCurrentContext/*3*/) ||
  15. (modalPresentationStyle == UIModalPresentationCustom/*4*/) ||
  16. (modalPresentationStyle == UIModalPresentationOverFullScreen/*5*/) ||
  17. (modalPresentationStyle == UIModalPresentationOverCurrentContext/*6*/)) {
  18. returnModalPresentationStyle = modalPresentationStyle;
  19. }else if((modalPresentationStyle == UIModalPresentationPageSheet/*1*/) ||
  20. (modalPresentationStyle == UIModalPresentationFormSheet/*2*/) ||
  21. (modalPresentationStyle == UIModalPresentationPopover/*7*/)) {
  22. returnModalPresentationStyle = UIModalPresentationFullScreen;
  23. }else{
  24. //UIModalPresentationBlurOverFullScreen/*8*/
  25. //UIModalPresentationNone/*-1*/
  26. //UIModalPresentationAutomatic/*-2*/
  27. returnModalPresentationStyle = UIModalPresentationFullScreen;
  28. }
  29. return returnModalPresentationStyle;
  30. }
  31. +(UIWindow*)getWindow {
  32. UIWindow* win = nil; //[UIApplication sharedApplication].keyWindow;
  33. for (id item in [UIApplication sharedApplication].windows) {
  34. if([item class] == [UIWindow class]) {
  35. if(!((UIWindow*)item).hidden) {
  36. win = item;
  37. break;
  38. }
  39. }
  40. }
  41. return win;
  42. }
  43. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
  44. {
  45. CGRect rect = CGRectMake(0, 0, size.width, size.height);
  46. UIGraphicsBeginImageContext(rect.size);
  47. CGContextRef context = UIGraphicsGetCurrentContext();
  48. CGContextSetFillColorWithColor(context, [color CGColor]);
  49. CGContextFillRect(context, rect);
  50. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  51. UIGraphicsEndImageContext();
  52. return image;
  53. }
  54. + (UIImage*) imageWithColor:(UIColor*)color andHeight:(CGFloat)height
  55. {
  56. CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, height);
  57. UIGraphicsBeginImageContext(rect.size);
  58. CGContextRef context = UIGraphicsGetCurrentContext();
  59. CGContextSetFillColorWithColor(context, [color CGColor]);
  60. CGContextFillRect(context, rect);
  61. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  62. UIGraphicsEndImageContext();
  63. return image;
  64. }
  65. //计算聊天消息的高 不是公用
  66. + (CGFloat)calculationHeightWithContent:(NSString *)content{
  67. CGFloat oneLineMaxW = SCREEN_WIDTH - (81+87);
  68. CGSize size = [content sizeWithFont:[UIFont systemFontOfSize:16] byWidth:oneLineMaxW textLineSpacing:5];
  69. if(size.height <= 40){
  70. return 40 + 15;
  71. }else{
  72. return size.height + 15 + 14*2;
  73. }
  74. }
  75. //计算聊天消息的宽 不是公用
  76. + (CGFloat)calculationWidthWithContent:(NSString *)content{
  77. CGFloat oneLineMaxW = SCREEN_WIDTH - (81+87);
  78. UILabel *tempLabel = [[UILabel alloc] init];
  79. tempLabel.frame = CGRectMake(0, 0, oneLineMaxW, 1);
  80. tempLabel.text = content;
  81. [tempLabel sizeToFit];
  82. if(tempLabel.width > oneLineMaxW){
  83. return SCREEN_WIDTH - 97 - oneLineMaxW;
  84. }else{
  85. return SCREEN_WIDTH - 97 - tempLabel.width;
  86. }
  87. }
  88. @end