// // UIView+Ext.h // HomeLinkProject // // Created by huangyibiao on 14-6-1. // Copyright (c) 2014年 huangyibiao. All rights reserved. // #import <UIKit/UIKit.h> ///< UIView的扩展类 ///< @author huangyibiao @interface UIView (Ext) /** * @brief Shortcut for frame.origin.x. * Sets frame.origin.x = originX */ @property (nonatomic) CGFloat originX; /** * @brief Shortcut for frame.origin.y * Sets frame.origin.y = originY */ @property (nonatomic) CGFloat originY; /** * @brief Shortcut for frame.origin.x + frame.size.width * Sets frame.origin.x = rightX - frame.size.width */ @property (nonatomic) CGFloat rightX; /** * @brief Shortcut for frame.origin.y + frame.size.height * Sets frame.origin.y = bottomY - frame.size.height */ @property (nonatomic) CGFloat bottomY; /** * @brief Shortcut for frame.size.width * Sets frame.size.width = width */ @property (nonatomic) CGFloat width; /** * @brief Shortcut for frame.size.height * Sets frame.size.height = height */ @property (nonatomic) CGFloat height; /** * @brief Shortcut for center.x * Sets center.x = centerX */ @property (nonatomic) CGFloat centerX; /** * @brief Shortcut for center.y * Sets center.y = centerY */ @property (nonatomic) CGFloat centerY; /** * @brief Shortcut for frame.origin */ @property (nonatomic) CGPoint origin; /** * @brief Shortcut for frame.size */ @property (nonatomic) CGSize size; ///< 移除此view上的所有子视图 - (void)removeAllSubviews; @end
// // UIView+Ext.m // HomeLinkProject // // Created by huangyibiao on 14-6-1. // Copyright (c) 2014年 huangyibiao. All rights reserved. // #import "UIView+Ext.h" @implementation UIView (Ext) - (CGFloat)originX { return self.frame.origin.x; } - (void)setOriginX:(CGFloat)originX { CGRect frame = self.frame; frame.origin.x = originX; self.frame = frame; return; } - (CGFloat)originY { return self.frame.origin.y; } - (void)setOriginY:(CGFloat)originY { CGRect frame = self.frame; frame.origin.y = originY; self.frame = frame; return; } - (CGFloat)rightX { return [self originX] + [self width]; } - (void)setRightX:(CGFloat)rightX { CGRect frame = self.frame; frame.origin.x = rightX - [self width]; self.frame = frame; return; } - (CGFloat)bottomY { return [self originY] + [self height]; } - (void)setBottomY:(CGFloat)bottomY { CGRect frame = self.frame; frame.origin.y = bottomY - [self height]; self.frame = frame; return; } - (CGFloat)centerX { return self.center.x; } - (void)setCenterX:(CGFloat)centerX { self.center = CGPointMake(centerX, self.center.y); return; } - (CGFloat)centerY { return self.center.y; } - (void)setCenterY:(CGFloat)centerY { self.center = CGPointMake(self.center.x, centerY); return; } - (CGFloat)width { return self.frame.size.width; } - (void)setWidth:(CGFloat)width { CGRect frame = self.frame; frame.size.width = width; self.frame = frame; return; } - (CGFloat)height { return self.frame.size.height; } - (void)setHeight:(CGFloat)height { CGRect frame = self.frame; frame.size.height = height; self.frame = frame; return; } - (CGPoint)origin { return self.frame.origin; } - (void)setOrigin:(CGPoint)origin { CGRect frame = self.frame; frame.origin = origin; self.frame = frame; return; } - (CGSize)size { return self.frame.size; } - (void)setSize:(CGSize)size { CGRect frame = self.frame; frame.size = size; self.frame = frame; return; } ///< 移除此view上的所有子视图 - (void)removeAllSubviews { for (UIView *view in self.subviews) { [view removeFromSuperview]; } return; } @end
时间: 2024-12-17 01:00:10