All Projects → LinXunFeng → Swiftyfitsize

LinXunFeng / Swiftyfitsize

Licence: mit
📱 Swifty screen adaptation solution (Support Objective-C and Swift)

Programming Languages

swift
15916 projects
objc
23 projects

Projects that are alternatives of or similar to Swiftyfitsize

react-native-awesome-pin
A highly interactive and customisable PIN code screen for React Native.
Stars: ✭ 28 (-84.78%)
Mutual labels:  screen, number
font-wonder-unit
Free and open source sans-serif font, brought to you by Wonder Unit.
Stars: ✭ 57 (-69.02%)
Mutual labels:  font, storyboard
Autoinch
优雅的iPhone全尺寸/等比例精准适配工具
Stars: ✭ 395 (+114.67%)
Mutual labels:  screen, storyboard
Iosevka
Versatile typeface for code, from code.
Stars: ✭ 13,137 (+7039.67%)
Mutual labels:  font
Ghosttypewriter
👻 A UILabel subclass that adds a typewriting animation effect
Stars: ✭ 159 (-13.59%)
Mutual labels:  storyboard
Goluwa
a game framework written in luajit
Stars: ✭ 173 (-5.98%)
Mutual labels:  font
Styled Theme
Extensible theming system for styled-components 💅
Stars: ✭ 183 (-0.54%)
Mutual labels:  font
Source Han Super Otc
Source Han & Noto CJK Mega/Ultra OTCs
Stars: ✭ 153 (-16.85%)
Mutual labels:  font
Powerline Web Fonts
Powerline Web Fonts for Chromebook
Stars: ✭ 178 (-3.26%)
Mutual labels:  font
Webfont
Awesome generator of webfont
Stars: ✭ 170 (-7.61%)
Mutual labels:  font
Teascreenpopupwindow
多类型筛选弹框、多数据筛选、多样化diy、单选or多选、必藏 (Multiple Type Screening Boxes, Multiple Data Screening, Diversified Diy, Single or Multiple Selection, Must Star)
Stars: ✭ 170 (-7.61%)
Mutual labels:  screen
Wgpu glyph
A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
Stars: ✭ 159 (-13.59%)
Mutual labels:  font
Libphonenumber Js
A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
Stars: ✭ 2,233 (+1113.59%)
Mutual labels:  number
React Native Input Spinner
An extensible input number spinner component for react-native highly customizable. This component enhance a text input for entering numeric values, with increase and decrease buttons.
Stars: ✭ 155 (-15.76%)
Mutual labels:  number
Lgbutton
A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.
Stars: ✭ 2,216 (+1104.35%)
Mutual labels:  font
Kwdrawercontroller
Drawer view controller that easy to use!
Stars: ✭ 154 (-16.3%)
Mutual labels:  storyboard
Vntnumberpickerpreference
NumberPicker Preference for Android
Stars: ✭ 176 (-4.35%)
Mutual labels:  number
Ws Scrcpy
Web client prototype for scrcpy.
Stars: ✭ 164 (-10.87%)
Mutual labels:  screen
Commonchinesecharacter
游戏开发中的常用汉字字库,包括3500常用字和7000常用字
Stars: ✭ 162 (-11.96%)
Mutual labels:  font
Inter
The Inter font family
Stars: ✭ 13,303 (+7129.89%)
Mutual labels:  font

SwiftyFitsize

Author CI Status Version License Platform visitors

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 时,适配后的 value 会再乘上 iPadFitMultiple
对比宽度,强制适配,不论是 iPhone 还是 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)

修改 参照宽度参照高度是否为iPhoneX系列的参照高度iPadFitMultiple 可以调用如下方法

/// 设置参照的相关参数
///
/// - Parameters:
///   - width: 参照的宽度
///   - height: 参照的高度
///   - isIPhoneXSeriesHeight: 是否为iPhoneX系列的参照高度
///   - iPadFitMultiple: iPad 在适配后所得值的倍数 (0 , 1]
SwiftyFitsize.reference(
  width: 414, 
  height: 896, 
  isIPhoneXSeriesHeight: true, 
  iPadFitMultiple: 0.5
)
二、支持 xib 和 storyboard
enum SwiftyFitType: Int {
    /// Original Value
    case none = 0
    /// ~
    case flexibleWidth = 1
    /// ≈
    case forceWidth = 2
    /// ∣
    case flexibleHeight = 3
    /// ∥
    case forceHeight = 4
    /// ∣=
    case flexibleSafeAreaCenterHeight = 5
    /// ∥=
    case forceSafeAreaCenterHeight = 6
    /// ∣-
    case flexibleSafeAreaWithoutTopHeight = 7
    /// ∥-
    case forceSafeAreaWithoutTopHeight = 8
}
  • Font Fitsize

支持的UI控件有: UILabel UIButton UITextView UITextField

FontFitType 的值请参考上方的 enum SwiftyFitType

xib-font

  • Constraint Fitsize

约束适配同上

xib-font

iPad 关于 ~ 在使用上的对比

~与≈的对比

三、Objective-C
  1. 由于 OC 不支持运算符重载,所以只能用宏来适配。

  2. XibStoryboard 则跟上方提及的使用方式相同。

Swift运算符OC宏 对应表

Swift运算符 OC宏
~ SF_xx
SFZ_xx
SF_FH_xx
SFZ_FH_xx
∣= SF_SCH_xx
∥= SFZ_SCH_xx
∣- SF_SBH_xx
∥- SFZ_SBH_xx

注: xx 支持如下类型 FontIntFloatPointSizeRectEdgeInsets

  • 导入
@import SwiftyFitsize;
  • 修改 参照宽度参照高度是否为iPhoneX系列的参照高度iPadFitMultiple
[SwiftyFitsize referenceWithWidth:414
                           height:896
            isIPhoneXSeriesHeight:YES
                  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

Other

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].