UIView
public extension UIView
-
SwifterSwift: Shake directions of a view.
- horizontal: Shake left and right.
- vertical: Shake up and down.
Declaration
Swift
enum ShakeDirection
-
Declaration
Swift
enum AngleUnit
-
SwifterSwift: Shake animations types.
- linear: linear animation.
- easeIn: easeIn animation.
- easeOut: easeOut animation.
- easeInOut: easeInOut animation.
Declaration
Swift
enum ShakeAnimationType
-
SwifterSwift: Border color of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var borderColor: UIColor? { get set }
-
SwifterSwift: Border width of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var borderWidth: CGFloat { get set }
-
SwifterSwift: Corner radius of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var cornerRadius: CGFloat { get set }
-
SwifterSwift: Height of view.
Declaration
Swift
var height: CGFloat { get set }
-
SwifterSwift: Check if view is in RTL format.
Declaration
Swift
var isRightToLeft: Bool { get }
-
SwifterSwift: Take screenshot of view (if applicable).
Declaration
Swift
var screenshot: UIImage? { get }
-
SwifterSwift: Shadow color of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var shadowColor: UIColor? { get set }
-
SwifterSwift: Shadow offset of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var shadowOffset: CGSize { get set }
-
SwifterSwift: Shadow opacity of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var shadowOpacity: Float { get set }
-
SwifterSwift: Shadow radius of view; also inspectable from Storyboard.
Declaration
Swift
@IBInspectable var shadowRadius: CGFloat { get set }
-
SwifterSwift: Size of view.
Declaration
Swift
var size: CGSize { get set }
-
SwifterSwift: Get view’s parent view controller
Declaration
Swift
var parentViewController: UIViewController? { get }
-
SwifterSwift: Width of view.
Declaration
Swift
var width: CGFloat { get set }
-
SwifterSwift: x origin of view.
Declaration
Swift
var x: CGFloat { get set }
-
SwifterSwift: y origin of view.
Declaration
Swift
var y: CGFloat { get set }
-
SwifterSwift: Recursively find the first responder.
Declaration
Swift
func firstResponder() -> UIView?
-
SwifterSwift: Set some or all corners radiuses of view.
Declaration
Swift
func roundCorners(_ corners: UIRectCorner, radius: CGFloat)
Parameters
corners
array of corners to change (example: [.bottomLeft, .topRight]).
radius
radius for selected corners.
-
SwifterSwift: Add shadow to view.
Declaration
Swift
func addShadow(ofColor color: UIColor = UIColor(red: 0.07, green: 0.47, blue: 0.57, alpha: 1.0), radius: CGFloat = 3, offset: CGSize = .zero, opacity: Float = 0.5)
Parameters
color
shadow color (default is #137992).
radius
shadow radius (default is 3).
offset
shadow offset (default is .zero).
opacity
shadow opacity (default is 0.5).
-
SwifterSwift: Add array of subviews to view.
Declaration
Swift
func addSubviews(_ subviews: [UIView])
Parameters
subviews
array of subviews to add to self.
-
SwifterSwift: Fade in view.
Declaration
Swift
func fadeIn(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil)
Parameters
duration
animation duration in seconds (default is 1 second).
completion
optional completion handler to run with animation finishes (default is nil)
-
SwifterSwift: Fade out view.
Declaration
Swift
func fadeOut(duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil)
Parameters
duration
animation duration in seconds (default is 1 second).
completion
optional completion handler to run with animation finishes (default is nil)
-
SwifterSwift: Load view from nib.
Declaration
Swift
class func loadFromNib(named name: String, bundle: Bundle? = nil) -> UIView?
Parameters
name
nib name.
bundle
bundle of nib (default is nil).
Return Value
optional UIView (if applicable).
-
SwifterSwift: Remove all subviews in view.
Declaration
Swift
func removeSubviews()
-
SwifterSwift: Remove all gesture recognizers from view.
Declaration
Swift
func removeGestureRecognizers()
-
SwifterSwift: Attaches gesture recognizers to the view. Attaching gesture recognizers to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesture recognizers.
Declaration
Swift
func addGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer])
Parameters
gestureRecognizers
The array of gesture recognizers to be added to the view.
-
SwifterSwift: Detaches gesture recognizers from the receiving view. This method releases gestureRecognizers in addition to detaching them from the view.
Declaration
Swift
func removeGestureRecognizers(_ gestureRecognizers: [UIGestureRecognizer])
Parameters
gestureRecognizers
The array of gesture recognizers to be removed from the view.
-
SwifterSwift: Rotate view by angle on relative axis.
Declaration
Swift
func rotate(byAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil)
Parameters
angle
angle to rotate view by.
type
type of the rotation angle.
animated
set true to animate rotation (default is true).
duration
animation duration in seconds (default is 1 second).
completion
optional completion handler to run with animation finishes (default is nil).
-
SwifterSwift: Rotate view to angle on fixed axis.
Declaration
Swift
func rotate(toAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil)
Parameters
angle
angle to rotate view to.
type
type of the rotation angle.
animated
set true to animate rotation (default is false).
duration
animation duration in seconds (default is 1 second).
completion
optional completion handler to run with animation finishes (default is nil).
-
SwifterSwift: Scale view by offset.
Declaration
Swift
func scale(by offset: CGPoint, animated: Bool = false, duration: TimeInterval = 1, completion: ((Bool) -> Void)? = nil)
Parameters
offset
scale offset
animated
set true to animate scaling (default is false).
duration
animation duration in seconds (default is 1 second).
completion
optional completion handler to run with animation finishes (default is nil).
-
SwifterSwift: Shake view.
Declaration
Swift
func shake(direction: ShakeDirection = .horizontal, duration: TimeInterval = 1, animationType: ShakeAnimationType = .easeOut, completion: (() -> Void)? = nil)
Parameters
direction
shake direction (horizontal or vertical), (default is .horizontal)
duration
animation duration in seconds (default is 1 second).
animationType
shake animation type (default is .easeOut).
completion
optional completion handler to run with animation finishes (default is nil).
-
SwifterSwift: Add Visual Format constraints.
Declaration
Swift
@available(iOS 9, *) func addConstraints(withFormat: String, views: UIView...)
Parameters
withFormat
visual Format language
views
array of views which will be accessed starting with index 0 (example: [v0], [v1], [v2]..)
-
SwifterSwift: Anchor all sides of the view into it’s superview.
Declaration
Swift
@available(iOS 9, *) func fillToSuperview()
-
anchor(top:left:bottom:right:topConstant:leftConstant:bottomConstant:rightConstant:widthConstant:heightConstant:)
SwifterSwift: Add anchors from any side of the current view into the specified anchors and returns the newly added constraints.
Declaration
Swift
@available(iOS 9, *) @discardableResult func anchor( top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) -> [NSLayoutConstraint]
Parameters
top
current view’s top anchor will be anchored into the specified anchor
left
current view’s left anchor will be anchored into the specified anchor
bottom
current view’s bottom anchor will be anchored into the specified anchor
right
current view’s right anchor will be anchored into the specified anchor
topConstant
current view’s top anchor margin
leftConstant
current view’s left anchor margin
bottomConstant
current view’s bottom anchor margin
rightConstant
current view’s right anchor margin
widthConstant
current view’s width
heightConstant
current view’s height
Return Value
array of newly added constraints (if applicable).
-
SwifterSwift: Anchor center X into current view’s superview with a constant margin value.
Declaration
Swift
@available(iOS 9, *) func anchorCenterXToSuperview(constant: CGFloat = 0)
Parameters
constant
constant of the anchor constraint (default is 0).
-
SwifterSwift: Anchor center Y into current view’s superview with a constant margin value.
Declaration
Swift
@available(iOS 9, *) func anchorCenterYToSuperview(constant: CGFloat = 0)
Parameters
withConstant
constant of the anchor constraint (default is 0).
-
SwifterSwift: Anchor center X and Y into current view’s superview
Declaration
Swift
@available(iOS 9, *) func anchorCenterSuperview()
-
SwifterSwift: Search all superviews until a view with the condition is found.
Declaration
Swift
func ancestorView(where predicate: (UIView?) -> Bool) -> UIView?
Parameters
predicate
predicate to evaluate on superviews.
-
SwifterSwift: Search all superviews until a view with this class is found.
Declaration
Swift
func ancestorView<T>(withClass name: T.Type) -> T? where T : UIView
Parameters
name
class of the view to search.