NSLayoutConstraint(MMMTemple)
@interface NSLayoutConstraint (MMMTemple)
/**
* Our wrapper over the corresponding method of NSLayoutConstraint extending the visual layout language a bit to support
* `safeAreaLayoutGuide` property introduced in iOS 11 and still be compatible with older versions of iOS.
* (See also `mmm_safeAreaLayoutGuide` in our extension of UIView.)
*
* To use it simply replace a reference to the superview edge "|" with a reference to a safe edge "<|".
*
* For example, if you have the following pre iOS 9 code:
*
* \code
* [NSLayoutConstraint activateConstraints:[NSLayoutConstraint
* constraintsWithVisualFormat:@"V:[_button]-(normalPadding)-|"
* options:0 metrics:metrics views:views
* ]];
* \endcode
*
* And now you want to make sure that the button sits above the safe bottom margin on iPhone X, then do this:
*
* \code
* [NSLayoutConstraint activateConstraints:[NSLayoutConstraint
* mmm_constraintsWithVisualFormat:@"V:[_button]-(normalPadding)-<|"
* options:0 metrics:metrics views:views
* ]];
* \endcode
*
* That's it. It'll anchor the button to the bottom of its superview on iOS 9 and 10, but anchor it to the bottom of
* its safeAreaLayoutGuide on iOS 11.
*
* Please note that using "|>" to pin to the top won't exclude the status bar on iOS 9 and 10.
*/
+ (NSArray<NSLayoutConstraint *> *)mmm_constraintsWithVisualFormat:(NSString *)format
options:(NSLayoutFormatOptions)opts
metrics:(nullable NSDictionary<NSString *,id> *)metrics
views:(nullable NSDictionary<NSString *,id> *)views;
/** A shortcut for `[NSLayoutConstraint activateConstraints:[NSLayoutConstraint mmm_constraintsWithVisualFormat:...`. */
+ (void)mmm_activateConstraintsWithVisualFormat:(NSString *)format
options:(NSLayoutFormatOptions)opts
metrics:(nullable NSDictionary<NSString *,id> *)metrics
views:(nullable NSDictionary<NSString *,id> *)views;
/** Missing counterparts for (de)activateConstraints, so constraint activation code looks the same for individual constraints. */
+ (void)activateConstraint:(NSLayoutConstraint *)constraint;
+ (void)deactivateConstraint:(NSLayoutConstraint *)constraint;
/** A missing convenience initializer including priority. */
+ (instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1
relatedBy:(NSLayoutRelation)relation
toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2
multiplier:(CGFloat)multiplier constant:(CGFloat)c
priority:(UILayoutPriority)priority;
/** A missing convenience initializer allowing to set identifier for this constraint. */
+ (instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1
relatedBy:(NSLayoutRelation)relation
toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2
multiplier:(CGFloat)multiplier constant:(CGFloat)c
identifier:(NSString *)identifier;
/** A missing convenience initializer allowing to set both priority and identifier for this constraint. */
+ (instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1
relatedBy:(NSLayoutRelation)relation
toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2
multiplier:(CGFloat)multiplier constant:(CGFloat)c
priority:(UILayoutPriority)priority
identifier:(NSString *)identifier;
/** A missing convenience initializer allowing to tag a bunch of visual constraints with the same identifier. */
+ (NSArray<__kindof NSLayoutConstraint *> *)constraintsWithVisualFormat:(NSString *)format
options:(NSLayoutFormatOptions)opts
metrics:(nullable NSDictionary<NSString *,id> *)metrics
views:(nullable NSDictionary<NSString *, id> *)views
identifier:(NSString *)identifier DEPRECATED_ATTRIBUTE;
@end
Undocumented
-
Our wrapper over the corresponding method of NSLayoutConstraint extending the visual layout language a bit to support
safeAreaLayoutGuide
property introduced in iOS 11 and still be compatible with older versions of iOS. (See alsommm_safeAreaLayoutGuide
in our extension of UIView.)To use it simply replace a reference to the superview edge “|” with a reference to a safe edge “<|”.
For example, if you have the following pre iOS 9 code:
\code [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@“V:[_button]-(normalPadding)-|” options:0 metrics:metrics views:views ]]; \endcode
And now you want to make sure that the button sits above the safe bottom margin on iPhone X, then do this:
\code [NSLayoutConstraint activateConstraints:[NSLayoutConstraint mmm_constraintsWithVisualFormat:@“V:[_button]-(normalPadding)-<|” options:0 metrics:metrics views:views ]]; \endcode
That’s it. It’ll anchor the button to the bottom of its superview on iOS 9 and 10, but anchor it to the bottom of its safeAreaLayoutGuide on iOS 11.
Please note that using “|>” to pin to the top won’t exclude the status bar on iOS 9 and 10.
Declaration
Objective-C
+ (nonnull NSArray<NSLayoutConstraint *> *) mmm_constraintsWithVisualFormat:(nonnull NSString *)format options:(NSLayoutFormatOptions)opts metrics: (nullable NSDictionary<NSString *, id> *)metrics views:(nullable NSDictionary<NSString *, id> *) views;
Swift
class func mmm_constraints(withVisualFormat format: String, options opts: NSLayoutConstraint.FormatOptions = [], metrics: [String : Any]?, views: [String : Any]?) -> [NSLayoutConstraint]
-
A shortcut for
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint mmm_constraintsWithVisualFormat:...
.Declaration
Objective-C
+ (void) mmm_activateConstraintsWithVisualFormat:(nonnull NSString *)format options:(NSLayoutFormatOptions)opts metrics:(nullable NSDictionary<NSString *, id> *)metrics views:(nullable NSDictionary<NSString *, id> *)views;
Swift
class func mmm_activateConstraints(withVisualFormat format: String, options opts: NSLayoutConstraint.FormatOptions = [], metrics: [String : Any]?, views: [String : Any]?)
-
Missing counterparts for (de)activateConstraints, so constraint activation code looks the same for individual constraints.
Declaration
Objective-C
+ (void)activateConstraint:(nonnull NSLayoutConstraint *)constraint;
Swift
class func activate(_ constraint: NSLayoutConstraint)
-
Undocumented
Declaration
Objective-C
+ (void)deactivateConstraint:(NSLayoutConstraint *)constraint;
Swift
class func deactivate(_ constraint: NSLayoutConstraint)
-
A missing convenience initializer including priority.
Declaration
Objective-C
+ (nonnull instancetype)constraintWithItem:(nonnull id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c priority:(UILayoutPriority)priority;
Swift
convenience init(item view1: Any, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation, toItem view2: Any?, attribute attr2: NSLayoutConstraint.Attribute, multiplier: CGFloat, constant c: CGFloat, priority: UILayoutPriority)
-
A missing convenience initializer allowing to set identifier for this constraint.
Declaration
Objective-C
+ (nonnull instancetype)constraintWithItem:(nonnull id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c identifier:(nonnull NSString *)identifier;
Swift
convenience init(item view1: Any, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation, toItem view2: Any?, attribute attr2: NSLayoutConstraint.Attribute, multiplier: CGFloat, constant c: CGFloat, identifier: String)
-
A missing convenience initializer allowing to set both priority and identifier for this constraint.
Declaration
Objective-C
+ (nonnull instancetype)constraintWithItem:(nonnull id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c priority:(UILayoutPriority)priority identifier:(nonnull NSString *)identifier;
Swift
convenience init(item view1: Any, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation, toItem view2: Any?, attribute attr2: NSLayoutConstraint.Attribute, multiplier: CGFloat, constant c: CGFloat, priority: UILayoutPriority, identifier: String)
-
Deprecated
A missing convenience initializer allowing to tag a bunch of visual constraints with the same identifier.
Declaration
Objective-C
+ (nonnull NSArray<__kindof NSLayoutConstraint *> *) constraintsWithVisualFormat:(nonnull NSString *)format options:(NSLayoutFormatOptions)opts metrics:(nullable NSDictionary<NSString *, id> *)metrics views:(nullable NSDictionary<NSString *, id> *)views identifier:(nonnull NSString *)identifier;
Swift
class func constraints(withVisualFormat format: String, options opts: NSLayoutConstraint.FormatOptions = [], metrics: [String : Any]?, views: [String : Any]?, identifier: String) -> [NSLayoutConstraint]