Simplifies work with layout in iOS. Provides set of tools for managing view's position, size and many other things.
- Copy content of
Source
folder to your project.
or
- Use
Frame
cocoapod
- iOS 9 and later
- Xcode 9 and later
- Swift 4
Height of string with attributes:
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)
Width of string with attributes:
let width = "Some text".frm.width(forHeight: 200, andAttributes: attributes)
Size that fits:
let constraintSize = CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)
let sizeThatFits = "Some text".frm.sizeThatFits(constraintSize, withAttributes: attributes)
Height of attributed string:
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)
Width of attributed string:
let width = attributedString.frm.width(forHeight: 200)
Size that fits:
let constraintSize = CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)
let sizeThatFits = attributedString.frm.sizeThatFits(constraintSize)
Label's height to fit attributed text:
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)
Inset:
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)
Offset:
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)
Frame
is available under the MIT license. See the LICENSE file for more info.