CGRectAlignmentExtensions 3.0.1

CGRectAlignmentExtensions 3.0.1

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新版本2020年3月
SPM支持 SPM

Marco Jonker 维护。



  • 作者:
  • Marco

CGRectAlignmentExtensions

CGRectAlignmentExtensions 是一个库,它使矩形之间的对齐变得简单。它包含在容器矩形的基础上对齐、适配宽高比例和填充矩形的功能。

安装

  1. 创建一个名为 "Podfile" 的文件
target '<PROJECT_NAME>' do
  use_frameworks!
  pod 'CGRectAlignmentExtensions', '>= 3.0'
end
  1. 在项目的终端文件夹中运行 pod install
pod install

有关安装 Cocoapods 的更多信息,请参阅:cocoapos

功能

  • alignIt
  • aligned
  • aspectFillIt
  • aspectFilled
  • aspectFitIt
  • aspectFitted
  • aspectFittedSquare
  • centerIt
  • centered
  • horizontalAlignIt
  • horizontalAligned
  • insetIt
  • insetted
  • verticalAlignIt
  • verticaAligned

示例

alignIt

将矩形沿水平方向向右外部对齐,沿垂直方向与另一个矩形的中心对齐

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.alignIt(to: rect1, with: .leftOutside, and: .center)

aligned

创建一个新对齐的矩形,水平拉伸并垂直对齐到底部

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.aligned(to: rect1, with: .stretchInside, and: .bottomInside)

aspectFillIt

将矩形适应到容器中

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.aspectFillIt(in: rect1)

aspectFilled

创建一个新的矩形,该矩形充满容器

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.aspectFilled(in: rect1)

aspectFitIt

将矩形适应到容器中

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.aspectFitIt(in: rect1)

aspectFitted

创建一个新矩形,此矩形按比例适配到容器中

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.aspectFitted(in: rect1)

aspectFittedSquare

创建一个适应矩形内部的正方形

let rect = CGRect(10, 10, 100, 100)

let square = rect.aspectFittedSquare()

centerIt

居中一个矩形

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.centerIt(to: rect1)

centered

创建一个新的居中矩形

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.centered(to: rect1)

horizontalAlignIt

将矩形水平右对齐到另一个矩形的上方

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.horizontalAlignIt(to: rect1, with: .rightOutside)

horizontalAligned

创建一个水平拉伸的新对齐矩形

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.horizontalAligned(to: rect1, with: .stretchInside)

insetIt

通过特定的 UIEdgeInsets 内陷一个矩形

let rect = CGRect(10, 10, 100, 100)
let insets = UIEdgeInsets(top: 5, left: 10, bottom: 15, right: 30)

rect.insetIt(by: insets)

insetted

创建一个内陷的特定 UIEdgeInsets 的矩形

let rect = CGRect(10, 10, 100, 100)
let insets = UIEdgeInsets(top: 5, left: 10, bottom: 15, right: 30)

let rect2 = rect.insetted(by: insets)

verticalAlignIt

将一个矩形水平地对齐到另一个矩形的外部顶部

let rect1 = CGRect(10, 10, 100, 100)
var rect2 = CGRect(90, 90, 50, 80)

rect2.verticalAlignIt(to: rect1, with: .topOutside)

verticalAligned

创建一个新的垂直拉伸对齐矩形

let rect1 = CGRect(10, 10, 100, 100)
let rect2 = CGRect(90, 90, 50, 80)

let rect3 = rect2.verticalAligned(to: rect1, with: .stretchInside)

其他信息

  • 创建者:[Marco](http://www.cacadu.eu)
  • Swift 版本:[^5.*](https://swiftlang.cn)
  • 文档:[cocoadocs](http://cocoadocs.org/docsets/CGRectAlignmentExtensions/3.0.0/)