5 Star 0 Fork 0

Gitee 极速下载 / SwiftyFitsize

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/LinXunFeng/SwiftyFitsize/archive/master.zip
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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. XibStoryboard 则跟上方提及的使用方式相同。

  • 导入
@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

Copyright (c) 2018 LinXunFeng <598600855@qq.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

SwiftyFitsize 是一个 Swift 的屏幕适配方案 展开 收起
Swift
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Swift
1
https://gitee.com/mirrors/SwiftyFitsize.git
git@gitee.com:mirrors/SwiftyFitsize.git
mirrors
SwiftyFitsize
SwiftyFitsize
master

搜索帮助

14c37bed 8189591 565d56ea 8189591