瀏覽代碼

YYCGUtilities: Fixed aspect fill rect calculation issue

ibireme 9 年之前
父節點
當前提交
4870be36b3
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      YYText/Utility/YYTextUtilities.m

+ 11 - 4
YYText/Utility/YYTextUtilities.m

@@ -200,11 +200,18 @@ CGRect YYTextCGRectFitWithContentMode(CGRect rect, CGSize size, UIViewContentMod
                 rect.size = CGSizeZero;
             } else {
                 CGFloat scale;
-                if (size.width / size.height < rect.size.width / rect.size.height &&
-                    mode == UIViewContentModeScaleAspectFit) {
-                    scale = rect.size.height / size.height;
+                if (mode == UIViewContentModeScaleAspectFit) {
+                    if (size.width / size.height < rect.size.width / rect.size.height) {
+                        scale = rect.size.height / size.height;
+                    } else {
+                        scale = rect.size.width / size.width;
+                    }
                 } else {
-                    scale = rect.size.width / size.width;
+                    if (size.width / size.height < rect.size.width / rect.size.height) {
+                        scale = rect.size.width / size.width;
+                    } else {
+                        scale = rect.size.height / size.height;
+                    }
                 }
                 size.width *= scale;
                 size.height *= scale;