Frame 1.2

Frame 1.2

Igor Matyushkin维护。




Frame 1.2

  • Igor Matyushkin

Frame

Frame

简化iOS中布局的工作。提供了一套用于管理视图位置、大小及其他许多功能的工具。

如何开始

  • Source文件夹的内容复制到您的项目中。

或者

  • 使用Frame cocoaapod

要求

  • iOS 9及以后版本
  • Xcode 9及以后版本
  • Swift 4

用法

字符串

具有属性的字符串高度

let attributes: [NSAttributedStringKey : Any] = [
    .font: UIFont.systemFont(ofSize: 36.0, weight: .thin),
    .kern: 0.5
]

let height = "Some text".frm.height(forWidth: 200, andAttributes: attributes)

具有属性的字符串宽度

let width = "Some text".frm.width(forHeight: 200, andAttributes: attributes)

合适的大小

let constraintSize = CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)
let sizeThatFits = "Some text".frm.sizeThatFits(constraintSize, withAttributes: attributes)

NSAttributedString

标注字符串的高度

let attributes: [NSAttributedStringKey : Any] = [
    .font: UIFont.systemFont(ofSize: 36.0, weight: .thin),
    .kern: 0.5
]

let attributedString = NSAttributedString(string: "Some text", attributes: attributes)
let height = attributedString.frm.height(forWidth: 200)

标注字符串的宽度

let width = attributedString.frm.width(forHeight: 200)

合适的大小

let constraintSize = CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)
let sizeThatFits = attributedString.frm.sizeThatFits(constraintSize)

UILabel

Label以适应标注文本的高度

let attributes: [NSAttributedStringKey : Any] = [
    .font: UIFont.systemFont(ofSize: 36.0, weight: .thin),
    .kern: 0.5
]

let attributedString = NSAttributedString(string: "Some text", attributes: attributes)
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 0))
let height = label.frm.height(forAttributedText: attributedString)

CGRect

内边距

let sourceFrame = CGRect(x: 20, y: 20, width: 500, height: 350)
let resultFrame = sourceFrame.frm.inset(top: 10, left: 10, bottom: 10, right: 10) // (30, 30, 480, 330)

偏移量

let sourceFrame = CGRect(x: 20, y: 20, width: 500, height: 350)
let resultFrame = sourceFrame.frm.offset(top: 10, left: 10, bottom: 10, right: 10) // (10, 10, 520, 370)

许可

框架受MIT许可。请参阅LICENSE文件以获取更多信息。