当需要调整视图的frame中的一个属性时,对UIViews进行处理是非常繁琐的。
你有多少次做过类似如下操作?
CGRect r = view.frame;
r.origin.x += 50.0;
view.frame = r;
这段代码不仅难以编写,也不易于阅读和维护。如果我们能够简单地完成类似以下操作,那该多好?
view.frameMinX += 50.0;
或者如何将视图固定在其父视图的右上角
view.frameTopRight = view.superview.boundsTopRight;
以下是为frame操作添加的以下属性
@property (nonatomic, assign) CGFloat frameMinX;
@property (nonatomic, assign) CGFloat frameMidX;
@property (nonatomic, assign) CGFloat frameMaxX;
@property (nonatomic, assign) CGFloat frameMinY;
@property (nonatomic, assign) CGFloat frameMidY;
@property (nonatomic, assign) CGFloat frameMaxY;
@property (nonatomic, assign) CGSize frameSize;
@property (nonatomic, assign) CGFloat frameWidth;
@property (nonatomic, assign) CGFloat frameHeight;
@property (nonatomic, assign) CGPoint frameTopLeft;
@property (nonatomic, assign) CGPoint frameTopCenter;
@property (nonatomic, assign) CGPoint frameTopRight;
@property (nonatomic, assign) CGPoint frameCenterLeft;
@property (nonatomic, assign) CGPoint frameCenter;
@property (nonatomic, assign) CGPoint frameCenterRight;
@property (nonatomic, assign) CGPoint frameBottomLeft;
@property (nonatomic, assign) CGPoint frameBottomCenter;
@property (nonatomic, assign) CGPoint frameBottomRight;
还有一些实用方法帮助操作frames
注意,任何调整方法都会取当前值并将给定的调整量+等于得到的调整值
- (void)setFrameX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height;
- (void)adjustFrameX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height;
- (void)setFrameX:(CGFloat)x y:(CGFloat)y;
- (void)adjustFrameX:(CGFloat)x y:(CGFloat)y;
- (void)setFrameWidth:(CGFloat)width height:(CGFloat)height;
- (void)adjustFrameWidth:(CGFloat)width height:(CGFloat)height;
一些额外的用于调整frame对齐的功能!
- (void)adjustFrameToWholePointsByRounding;
- (void)adjustFrameToWholePointsByFlooring;
- (void)adjustFrameToWholePointsByCeiling;
填充和扩展frames也非常繁杂,所以我们有一些快速的帮助函数来完成此操作!
- (void)insetFrameBy:(CGFloat)amount;
- (void)insetFrameByWidth:(CGFloat)widthAmount height:(CGFloat)heightAmount;
- (void)expandFrameBy:(CGFloat)amount;
- (void)expandFrameByWidth:(CGFloat)widthAmount height:(CGFloat)heightAmount;
在iOS中,自动调整大小很棒,但有时你只想允许宽度或高度进行调整。
- (void)sizeWidthToFit;
- (void)sizeHeightToFit;
处理边界不太烦人,但有时一些快速助手可以使代码更容易、更快,但这些属性是只读的。
@property (nonatomic, assign, readonly) CGFloat boundsMinX;
@property (nonatomic, assign, readonly) CGFloat boundsMidX;
@property (nonatomic, assign, readonly) CGFloat boundsMaxX;
@property (nonatomic, assign, readonly) CGFloat boundsMinY;
@property (nonatomic, assign, readonly) CGFloat boundsMidY;
@property (nonatomic, assign, readonly) CGFloat boundsMaxY;
@property (nonatomic, assign, readonly) CGSize boundsSize;
@property (nonatomic, assign, readonly) CGFloat boundsWidth;
@property (nonatomic, assign, readonly) CGFloat boundsHeight;
@property (nonatomic, assign, readonly) CGPoint boundsTopLeft;
@property (nonatomic, assign, readonly) CGPoint boundsTopCenter;
@property (nonatomic, assign, readonly) CGPoint boundsTopRight;
@property (nonatomic, assign, readonly) CGPoint boundsCenterLeft;
@property (nonatomic, assign, readonly) CGPoint boundsCenter;
@property (nonatomic, assign, readonly) CGPoint boundsCenterRight;
@property (nonatomic, assign, readonly) CGPoint boundsBottomLeft;
@property (nonatomic, assign, readonly) CGPoint boundsBottomCenter;
@property (nonatomic, assign, readonly) CGPoint boundsBottomRight;
Cocoapods可用,只需将其添加到Podfile中即可!
pod "ZWPTouchFrames"
ZWPTouchFrames 具有完整的 SenTesting 套件以确保所有控件都没有错误!祝您享受。
即是MIT许可证,也称为随意使用。