The Wayback Machine - http://web.archive.org/web/20200803153239/https://github.com/LinXunFeng/SwiftyFitsize
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

SwiftyFitsize

CI Status Version License Platform

Example

克隆或下载仓库到本地å?Žï¼Œè¯·å…ˆè¿?行 pod install , å†?打开 SwiftyFitsize.xcworkspace

Requirements

  • iOS 9.0+
  • Xcode 10.2+
  • Swift 5+

Installation

  • Cocoapods
use_frameworks!
pod 'SwiftyFitsize'

Exhibition

iPhone

iPad

Usage

一ã€?æ“?作符 ~ 与 ≈

无论是 ~ 还是 ≈ 对 iPhone 的适é…?效果是一样的。而对 iPad 而言,iPad 的宽度太大,使用 ≈ 还是会按宽度比例进行è¿?算,就会显示特别臃肿,这时使用 ~ 在显示上就会比较å?ˆé€‚。

  • ~ 在 ≈ 的基础上针对 iPad 的适é…?大å°?å?Žå†?去乘上 iPadFitMultiple 。

  • 一般情况下直接使用 ~ å?³å?¯ã€‚

~ : 当设备为 iPad 时,适é…?å?Žçš„值会与 iPadFitMultiple 相乘

100~
UIFont.systemFont(ofSize: 14)~
CGPoint(x: 10, y: 10)~
CGRect(x: 10, y: 10, width: 100, height: 100)~
UIEdgeInsetsMake(10, 10, 10, 10)~

≈ : (option + x) 适é…?å?Žçš„值ä¸?会与 iPadFitMultiple 相乘

100≈
UIFont.systemFont(ofSize: 14)≈
CGPoint(x: 10, y: 10)≈
CGRect(x: 10, y: 10, width: 100, height: 100)≈
UIEdgeInsetsMake(10, 10, 10, 10)≈

修改 å?‚照宽度 与 iPadFitMultiple å?¯ä»¥è°ƒç”¨ä»¥ä¸‹æ–¹æ³•

/// 设置å?‚照的相关å?‚æ•°
///
/// - Parameters:
///   - width: �照的宽度
///   - iPadFitMultiple: iPad 在适é…?å?Žæ‰€å¾—值的å€?数 (0 , 1]
SwiftyFitsize.reference(width: 414, iPadFitMultiple: 0.5)
二ã€?支æŒ? xib 和 storyboard
enum SwiftyFitType: Int {
    /// Original Value
    case none = 0
    /// ~
    case flexible = 1
    /// ≈
    case force = 2
}
  • Font Fitsize

支æŒ?的UI控件有: UILabel UIButton UITextView UITextField

FontFitType 的值请å?‚考上方的 enum SwiftyFitType

xib-font

  • Constraint Fitsize

约æ?Ÿé€‚é…?å?Œä¸Š

xib-font

iPad 关于 ~ 与 ≈ 在使用上的对比

~与≈的对比

三ã€?Objective-C
  1. 由于 OC ä¸?支æŒ?è¿?算符é‡?载,所以å?ªèƒ½ç”¨å®?æ?¥é€‚é…?。

  2. Xib 和 Storyboard 则跟上方æ??å?Šçš„使用方å¼?相å?Œã€‚

  • 导入
@import SwiftyFitsize;
  • 修改 å?‚照宽度 与 iPadFitMultiple
[SwiftyFitsize referenceWithWidth:414 iPadFitMultiple:0.6];
  • ~
UIFont *font = [UIFont systemFontOfSize:14];

UIFont *font1 = font.sf;
UIFont *font2 = SF_Font(font);

CGFloat num = SF_Float(14);
CGPoint point = SF_Point(CGPointMake(10, 10));
CGSize size = SF_Size(CGSizeMake(100, 100));
CGRect rect = SF_Rect(CGRectMake(10, 10, 100, 100));
UIEdgeInsets edge = SF_EdgeInsets(UIEdgeInsetsMake(0, 0, 100, 100));
  • ≈
UIFont *font1 = font.sfz;
UIFont *font2 = SFZ_Font(font);

CGFloat num = SFZ_Float(14);
CGPoint point = SFZ_Point(CGPointMake(10, 10));
CGSize size = SFZ_Size(CGSizeMake(100, 100));
CGRect rect = SFZ_Rect(CGRectMake(10, 10, 100, 100));
UIEdgeInsets edge = SFZ_EdgeInsets(UIEdgeInsetsMake(0, 0, 100, 100));

Misc

下é?¢åˆ—出一些设备对应的分辨率,方便查找

设备 逻辑分辨率(point) 设备分辨率(pixel)
SE 320x568 640x1136
6(S)ï¼?7ï¼?8 375x667 750x1334
6(S)+ï¼?7+ï¼?8+ 414x736 1080x1920
X(S) 375x812 1125x2436
XR 414x896 828x1792
XS Max 414x896 1242x2688

License

SwiftyFitsize is available under the MIT license. See the LICENSE file for more info.

Author

You can’t perform that action at this time.