众多扩展 1.1.2

众多扩展 1.1.2

hlwanhoj 维护。



  • hlwanhoj

众多扩展

CI Status Version License Platform

一组保存您的代码并可节省时间的 Swift 扩展。

特点

根据其依赖关系对扩展进行分组,这些依赖关系包括

  • Foundation

    • CGPoint

      • 数学
      -CGPoint(x: -3, y: 5)                                       // {x 3 y -5}
      CGPoint(x: -3, y: 5) + 4                                    // {x 1 y 9}
      CGPoint(x: -3, y: 5) - 4                                    // {x -7 y 1}
      CGPoint(x: -3, y: 5) * 3                                    // {x -9 y 15}
      CGPoint(x: -3, y: 5) / 2                                    // {x -1.5 y 2.5}
    • CGSize

      • 数学
      -CGSize(width: 20, height: 54)                              // {w -20 h -54}
      CGSize(width: 20, height: 54) + 10                          // {w 30 h 64}
      CGSize(width: 20, height: 54) - 10                          // {w 10 h 44}
      CGSize(width: 20, height: 54) * 3                           // {w 60 h 162}
      CGSize(width: 20, height: 54) / 2                           // {w 10 h 27}
    • CGRect

      • 锚点,例如 topLeftcenterbottomRight
      let rect = CGRect(x: 5, y: -10, width: 50, height: 60)
      rect.topLeft                                                // {x 5 y -10}
      rect.topCenter                                              // {x 30 y -10}
      rect.topRight                                               // {x 55 y -10}
      rect.centerLeft                                             // {x 5 y 20}
      rect.center                                                 // {x 30 y 20}
      rect.centerRight                                            // {x 55 y 20}
      rect.bottomLeft                                             // {x 5 y 50}
      rect.bottomCenter                                           // {x 30 y 50}
      rect.bottomRight                                            // {x 55 y 50}
      • 锚点自动贴合
      let rect2 = CGRect(x: 25, y: 40, width: 100, height: 20)
      
      // Move `rect` such that it's top left is at `rect2`'s center
      rect.snapping(.topLeft, to: rect2.center)                   // {x 75 y 50 w 50 h 60}
      
      // Move `rect` such that it's bottom right is at `rect2`'s center left
      rect.snapping(.bottomRight, to: rect2.centerLeft)           // {x -25 y -10 w 50 h 60}
      • 边缘,例如 lefttop
      rect.top                                                    // -10
      rect.left                                                   // 5
      rect.bottom                                                 // 50
      rect.right                                                  // 55
      • 边缘自动贴合
      // Move `rect` such that it's left is on `rect2`'s right
      rect.snapping(.left, to: rect2.right)                       // {x 125 y -10 w 50 h 60}
      
      // Move `rect` such that it's bottom is at `rect2`'s bottom
      rect.snapping(.bottom, to: rect2.bottom)                    // {x 5 y 0 w 50 h 60}
    • Bundle

      • Info.plist
      Bundle.main.releaseVersion                                  // returns CFBundleShortVersionString
      Bundle.main.buildVersion                                    // returns CFBundleVersion
      Bundle.main.displayName                                     // returns CFBundleDisplayName
      Bundle.main.shortName                                     // returns CFBundleName
  • UIKit

    • UIEdgeInsets

      • 数学
      -UIEdgeInsets(top: 12, left: 6, bottom: -8, right: -10)     // {top: -12, left: -6, bottom: 8, right: 10}
      • 初始化方法
      UIEdgeInsets.all(value: 3)                                  // {top: 3, left: 3, bottom: 3, right: 3}
      UIEdgeInsets.symmetric(vertical: 10)                        // {top: 10, left: 0, bottom: 10, right: 0}
      UIEdgeInsets.only(left: 7, bottom: 3)                       // {top: 0, left: 7, bottom: 3, right: 0}
      • 水平/垂直求和
      let insets = UIEdgeInsets(top: 12, left: 6, bottom: 8, right: 10)
      insets.horizontals                                          // 16
      insets.verticals                                            // 20
    • UIImage

      • 从颜色创建
      • 缩放
      • 扩展画布

需求

  • iOS 11.0+
  • Xcode 12+
  • Swift 5+

安装

众多扩展可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 即可

pod 'LotsOfExtensions'

或者只安装特定依赖的扩展,例如 Foundation

pod 'LotsOfExtensions/Foundation'

作者

hlwanhoj, [email protected]

许可证

LotsOfExtensions可在MIT许可证下使用。更多信息请参阅LICENSE文件。