Declarative UIKit for iOS apps
EXTENSION
UIView
public extension UIView
centerHorizontally
var centerHorizontally: DHDHStack
Put this view in a UIHStack with a spacer before and after
declaredWithRedLines
var declaredWithRedLines: UIView
Add a border, corner radius, and light background color to inspect a view
inspect
var inspect: UIView
Add a border, corner radius, and light background color to debug a view
cornerRadius
var cornerRadius: CGFloat
Access the layer’s corner radius with this helper, also properely set masksToBounds
addDivider(at:color:weight:insets:)
@discardableResult func addDivider(at position: DHDDividerPosition, color: UIColor, weight: CGFloat = 1.0 / UIScreen.main.scale, insets: UIEdgeInsets = .zero) -> UIView
Create a horizontal line at the specified position, color, weight, using the insets
UIView
as the dividerbackground(color:)
@discardableResult func background(color: UIColor?) -> Self
Set the background color of this view
UIColor
Name | Description |
---|---|
color | optional UIColor |
identified(_:)
@objc @discardableResult func identified(_ value: String) -> Self
Set the .accessibilityIdentifier
of this view
String
value to setName | Description |
---|---|
value | the String value to set |
margin(horizontal:vertical:)
@discardableResult func margin(horizontal: CGFloat, vertical: CGFloat) -> Self
Set the margin of this view
CGFloat
of the widthCGFloat
of the heightName | Description |
---|---|
horizontal | the CGFloat of the width |
vertical | the CGFloat of the height |
margin(top:right:bottom:left:)
@discardableResult func margin(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) -> Self
Set the margin of each side of this view
CGFloat
of the topCGFloat
of the rightCGFloat
of the bottomCGFloat
of the leftName | Description |
---|---|
top | the CGFloat of the top |
right | the CGFloat of the right |
bottom | the CGFloat of the bottom |
left | the CGFloat of the left |
center(to:heightLessThanOrEqualToConstant:widthLessThanOrEqualToConstant:)
func center(to: UIView, heightLessThanOrEqualToConstant: CGFloat, widthLessThanOrEqualToConstant: CGFloat)
Put this view in the center of a containing view
Name | Description |
---|---|
to | the containing view, make sure this view is a subview |
heightLessThanOrEqualToConstant | . |
widthLessThanOrEqualToConstant | . |
pin(to:withVerticalPadding:withHorizontalPadding:)
func pin(to superView: UIView, withVerticalPadding: CGFloat = 0, withHorizontalPadding: CGFloat = 0)
Use constraints to pin this to a superview
Name | Description |
---|---|
superView | . |
withVerticalPadding | . |
withHorizontalPadding | . |
rounded(by:)
@discardableResult func rounded(by radius: CGFloat) -> Self
Set the corner radius of this view
Name | Description |
---|---|
radius | how much to round the corner |
tagged(_:)
@discardableResult func tagged(_ tag: Int) -> Self
Set the tag
of this view
Int
of a tagName | Description |
---|---|
tag | an Int of a tag |
toPreview()
func toPreview() -> some View
Example usage:
// MARK: - Preview
import SwiftUI
struct UIViewPreview: PreviewProvider {
static var previews: some View {
UIView().toPreview()
}
}