UIView(MMMTemple)

@interface UIView (MMMTemple)

A few shorthands for UIView.

  • A wrapper for the center and bounds.size properties similar to ‘frame’, but not taking the current transform into account.

    • Handy when there is a transform applied to a view already, but we want to set its frame in normal state.

    Declaration

    Objective-C

    @property (nonatomic, setter=mmm_setRect:) CGRect mmm_rect;

    Swift

    var mmm_rect: CGRect { get set }
  • A wrapper for the size component of bounds property.

    Declaration

    Objective-C

    @property (nonatomic, setter=mmm_setSize:) CGSize mmm_size;

    Swift

    var mmm_size: CGSize { get set }
  • A safer version of safeAreaLayoutGuide that attempts to avoid layout loops happening when a view using it

    • is transformed in certain “inconvenient” way. (Apple Feedback ID: FB7609936.)

    Declaration

    Objective-C

    @property (nonatomic, readonly) UILayoutGuide *_Nonnull mmm_safeAreaLayoutGuide;

    Swift

    var mmm_safeAreaLayoutGuide: UILayoutGuide { get }
  • Effective safeAreaInsets as seen by mmm_safeAreaLayoutGuide.

    Declaration

    Objective-C

    @property (nonatomic, readonly) UIEdgeInsets mmm_safeAreaInsets;

    Swift

    var mmm_safeAreaInsets: UIEdgeInsets { get }
  • Constraints anchoring the given view within the receiver according to horizontal and vertical alignment flags. Note that constrains are not added into the reciever automatically. It is recommended to use this method instead of the mmm_addConstraintsForSubview:* bunch.

    Declaration

    Objective-C

    - (nonnull NSArray<NSLayoutConstraint *> *)
        mmm_constraintsAligningView:(nonnull UIView *)subview
                       horizontally:
                           (MMMLayoutHorizontalAlignment)horizontalAlignment
                         vertically:(MMMLayoutVerticalAlignment)verticalAlignment
                             insets:(UIEdgeInsets)insets;

    Swift

    func mmm_constraintsAligningView(_ subview: UIView, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment, vertically verticalAlignment: MMMLayoutVerticalAlignment, insets: UIEdgeInsets) -> [NSLayoutConstraint]
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_constraintsAligningView:(UIView *)subview
    	horizontally:(MMMLayoutHorizontalAlignment)horizontalAlignment DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_constraintsAligningView(_ subview: UIView, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment) -> [NSLayoutConstraint]
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_constraintsAligningView:(UIView *)subview
    	vertically:(MMMLayoutVerticalAlignment)verticalAlignment DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_constraintsAligningView(_ subview: UIView, vertically verticalAlignment: MMMLayoutVerticalAlignment) -> [NSLayoutConstraint]
  • Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_constraintsAligningGuide:(UILayoutGuide *)guide
    	horizontally:(MMMLayoutHorizontalAlignment)horizontalAlignment
    	vertically:(MMMLayoutVerticalAlignment)verticalAlignment
    	insets:(UIEdgeInsets)insets NS_SWIFT_NAME(mmm_constraints(aligning:horizontally:vertically:insets:));

    Swift

    func mmm_constraints(aligning guide: UILayoutGuide, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment, vertically verticalAlignment: MMMLayoutVerticalAlignment, insets: UIEdgeInsets) -> [NSLayoutConstraint]
  • Adds contraints anchoring the given view within the receiver according to horizontal and vertical alignment flags. (This is a shortcut for calling mmm_constraintsAligningView:horizontally:vertically:insets: and adding the contraints returned.)

    Declaration

    Objective-C

    - (nonnull NSArray<NSLayoutConstraint *> *)
        mmm_addConstraintsAligningView:(nonnull UIView *)subview
                          horizontally:
                              (MMMLayoutHorizontalAlignment)horizontalAlignment
                            vertically:(MMMLayoutVerticalAlignment)verticalAlignment
                                insets:(UIEdgeInsets)insets;

    Swift

    func mmm_addConstraintsAligningView(_ subview: UIView, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment, vertically verticalAlignment: MMMLayoutVerticalAlignment, insets: UIEdgeInsets) -> [NSLayoutConstraint]
  • Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_addConstraintsAligningView:(UIView *)subview
    	horizontally:(MMMLayoutHorizontalAlignment)horizontalAlignment
    	vertically:(MMMLayoutVerticalAlignment)verticalAlignment;

    Swift

    func mmm_addConstraintsAligningView(_ subview: UIView, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment, vertically verticalAlignment: MMMLayoutVerticalAlignment) -> [NSLayoutConstraint]
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_addConstraintsAligningView:(UIView *)subview
    	horizontally:(MMMLayoutHorizontalAlignment)horizontalAlignment DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_addConstraintsAligningView(_ subview: UIView, horizontally horizontalAlignment: MMMLayoutHorizontalAlignment) -> [NSLayoutConstraint]
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_addConstraintsAligningView:(UIView *)subview
    	vertically:(MMMLayoutVerticalAlignment)verticalAlignment DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_addConstraintsAligningView(_ subview: UIView, vertically verticalAlignment: MMMLayoutVerticalAlignment) -> [NSLayoutConstraint]
  • Not yet activated constraints implementing a common layout idiom used with text:

    • the given view is centered within the receiver,
    • certain minimum padding is ensured on the sides,
    • if maxWidth > 0, then the width of the view is limited to maxWidth, so it does not grow too wide e.g. on iPad.

    Declaration

    Objective-C

    - (nonnull NSArray<NSLayoutConstraint *> *)
        mmm_constraintsHorizontallyCenteringView:(nonnull UIView *)view
                                      minPadding:(CGFloat)minPadding
                                        maxWidth:(CGFloat)maxWidth;
  • A shortcut activating constraints returned by mmm_constraintsHorizontallyCenteringView:minPadding:maxWidth:.

    Declaration

    Objective-C

    - (void)mmm_addConstraintsHorizontallyCenteringView:(nonnull UIView *)view
                                             minPadding:(CGFloat)minPadding
                                               maxWidth:(CGFloat)maxWidth;
  • A shortcut activating constraints returned by mmm_constraintsHorizontallyCenteringView:minPadding:maxWidth:

    • setting maxWidth to zero.

    Declaration

    Objective-C

    - (void)mmm_addConstraintsHorizontallyCenteringView:(nonnull UIView *)view
                                             minPadding:(CGFloat)minPadding;

To be deprecated soon

  • Deprecated

    Adds constraints anchoring the given subview within the receiver according to horizontal and vertical alignment flags. The constraints are also returned, so the caller can remove them later, for example.

    Declaration

    Objective-C

    - (nonnull NSArray<NSLayoutConstraint *> *)
        mmm_addConstraintsForSubview:(nonnull UIView *)subview
                 horizontalAlignment:
                     (UIControlContentHorizontalAlignment)horizontalAlignment
                   verticalAlignment:
                       (UIControlContentVerticalAlignment)verticalAlignment
                              insets:(UIEdgeInsets)insets;

    Swift

    func mmm_addConstraints(forSubview subview: UIView, horizontalAlignment: UIControl.ContentHorizontalAlignment, verticalAlignment: UIControl.ContentVerticalAlignment, insets: UIEdgeInsets) -> [NSLayoutConstraint]
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (NSArray<NSLayoutConstraint *> *)mmm_addConstraintsForSubview:(UIView *)subview
    	horizontalAlignment:(UIControlContentHorizontalAlignment)horizontalAlignment
    	verticalAlignment:(UIControlContentVerticalAlignment)verticalAlignment
    	DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_addConstraints(forSubview subview: UIView, horizontalAlignment: UIControl.ContentHorizontalAlignment, verticalAlignment: UIControl.ContentVerticalAlignment) -> [NSLayoutConstraint]
  • Adds constraints and two hidden auxiliary views ensuring that the space between the top of the subview and topAttribute of topItem is in ‘ratio’ proportion to the space between the bottom of the subview and bottomAttribute of bottomItem.

    To be clear: ratio = (top space) / (bottom space)

    So you need to use 1 when you want the same size, not 0.5, for example.

    The given priority will be used for the constraints between the heights of the aux views.

    Declaration

    Objective-C

    - (void)mmm_addVerticalSpaceRatioConstraintsForSubview:(nonnull UIView *)subview
                                                   topItem:(nonnull id)topItem
                                              topAttribute:
                                                  (NSLayoutAttribute)topAttribute
                                                bottomItem:(nonnull id)bottomItem
                                           bottomAttribute:
                                               (NSLayoutAttribute)bottomAttribute
                                                     ratio:(CGFloat)ratio
                                                  priority:
                                                      (UILayoutPriority)priority;

    Swift

    func mmm_addVerticalSpaceRatioConstraints(forSubview subview: UIView, topItem: Any, topAttribute: NSLayoutConstraint.Attribute, bottomItem: Any, bottomAttribute: NSLayoutConstraint.Attribute, ratio: CGFloat, priority: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_addVerticalSpaceRatioConstraintsForSubview:(UIView *)subview
    	topItem:(id)topItem topAttribute:(NSLayoutAttribute)topAttribute
    	bottomItem:(id)bottomItem bottomAttribute:(NSLayoutAttribute)bottomAttribute
    	ratio:(CGFloat)ratio;

    Swift

    func mmm_addVerticalSpaceRatioConstraints(forSubview subview: UIView, topItem: Any, topAttribute: NSLayoutConstraint.Attribute, bottomItem: Any, bottomAttribute: NSLayoutConstraint.Attribute, ratio: CGFloat)
  • Deprecated

    Adds constrains and a hidden auxiliary view ensuring that specified item / attribute vertically divides the subview in the specified ratio. Unlike the previous function the ratio here is given not as (top space / bottom space), but as (top space / (top space + bottom space)). Sorry for the confusion, deprecating this one for now.

    Declaration

    Objective-C

    - (void)mmm_addVerticalSpaceRatioConstraintsForSubview:(nonnull UIView *)subview
                                                      item:(nonnull id)item
                                                 attribute:
                                                     (NSLayoutAttribute)attribute
                                                     ratio:(CGFloat)ratio;

    Swift

    func mmm_addVerticalSpaceRatioConstraints(forSubview subview: UIView, item: Any, attribute: NSLayoutConstraint.Attribute, ratio: CGFloat)
  • Shortcuts for compression resistance and hugging priorities.

    Declaration

    Objective-C

    - (void)mmm_setVerticalCompressionResistance:(UILayoutPriority)priority;

    Swift

    func mmm_setVerticalCompressionResistance(_ priority: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_setHorizontalCompressionResistance:(UILayoutPriority)priority;

    Swift

    func mmm_setHorizontalCompressionResistance(_ priority: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_setVerticalHuggingPriority:(UILayoutPriority)priority;

    Swift

    func mmm_setVerticalHuggingPriority(_ priority: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_setHorizontalHuggingPriority:(UILayoutPriority)priority;

    Swift

    func mmm_setHorizontalHuggingPriority(_ priority: UILayoutPriority)
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (void)mmm_setVerticalCompressionResistance:(UILayoutPriority)compressionResistance hugging:(UILayoutPriority)hugging DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_setVerticalCompressionResistance(_ compressionResistance: UILayoutPriority, hugging: UILayoutPriority)
  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (void)mmm_setHorizontalCompressionResistance:(UILayoutPriority)compressionResistance hugging:(UILayoutPriority)hugging DEPRECATED_ATTRIBUTE;

    Swift

    func mmm_setHorizontalCompressionResistance(_ compressionResistance: UILayoutPriority, hugging: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_setCompressionResistanceHorizontal:(UILayoutPriority)horizontal
    	vertical:(UILayoutPriority)vertical NS_SWIFT_NAME(mmm_setCompressionResistance(horizontal:vertical:));

    Swift

    func mmm_setCompressionResistance(horizontal: UILayoutPriority, vertical: UILayoutPriority)
  • Undocumented

    Declaration

    Objective-C

    - (void)mmm_setHuggingHorizontal:(UILayoutPriority)horizontal
    	vertical:(UILayoutPriority)vertical NS_SWIFT_NAME(mmm_setHugging(horizontal:vertical:));

    Swift

    func mmm_setHugging(horizontal: UILayoutPriority, vertical: UILayoutPriority)