MMMLayoutUtils
Objective-C
@interface MMMLayoutUtils : NSObject
Swift
class MMMLayoutUtils : NSObject
This is to group a few simple layout helpers.
-
A rect with the given size positioned inside of the target rect in such a way that anchor points of both rects align.
Anchor points are given relative to the sizes of the corresponding rects, similar to CALayer’s
anchorPoint
property. For example,CGPointMake(0.5, 0.5)
represents a center of any rect;CGPointMake(1, 0.5)
means the center point of the right vertical edge.Note that the origin of the rect returned is rounded to the nearest pixels (not points!).
See
rectWithSize:inRect:contentMode:
for a shortcut supporting UIViewContentMode.Declaration
Objective-C
+ (CGRect)rectWithSize:(CGSize)size anchor:(CGPoint)anchor withinRect:(CGRect)targetRect anchor:(CGPoint)targetAnchor;
Swift
class func rect(withSize size: CGSize, anchor: CGPoint, withinRect targetRect: CGRect, anchor targetAnchor: CGPoint) -> CGRect
-
A shortcut for the above method with anchors being the same for both source and target rect. (This way the resulting rect will be always inside of the target one, assuming anchors are within [0; 1] range.)
Declaration
Objective-C
+ (CGRect)rectWithSize:(CGSize)size withinRect:(CGRect)targetRect anchor:(CGPoint)anchor;
Swift
class func rect(withSize size: CGSize, withinRect targetRect: CGRect, anchor: CGPoint) -> CGRect
-
A frame for the
sourceRect
positioned within thetargetRect
according to standardUIViewContentMode
flags related to the layout (i.e. all exceptUIViewContentModeRedraw
).Note that the origin of the resulting rectangle is always rounded to the nearest pixel.
Declaration
Objective-C
+ (CGRect)rectWithSize:(CGSize)size withinRect:(CGRect)targetRect contentMode:(UIViewContentMode)contentMode;
Swift
class func rect(withSize size: CGSize, withinRect targetRect: CGRect, contentMode: UIView.ContentMode) -> CGRect
-
A frame of the given size with its center at the specified point (assuming the center is defined by the given anchor point).
Note that the origin of the resulting rectangle is rounded to the nearest pixel boundary.
Declaration
Objective-C
+ (CGRect)rectWithSize:(CGSize)size atPoint:(CGPoint)center anchor:(CGPoint)anchor;
Swift
class func rect(withSize size: CGSize, atPoint center: CGPoint, anchor: CGPoint) -> CGRect
-
Same as rectWithSize:center:anchor: with anchor set to (0.5, 0.5).
Declaration
Objective-C
+ (CGRect)rectWithSize:(CGSize)size center:(CGPoint)center;
Swift
class func rect(withSize size: CGSize, center: CGPoint) -> CGRect