圆角View
- (void) cornerRadius:(CGFloat) arc { self.layer.cornerRadius = arc; self.layer.masksToBounds = YES; }
2.避免结构体不能复制,导致UIView 中 x,y,with,height复制繁琐
@property (nonatomic, assign) float x; @property (nonatomic, assign) float y; @property (nonatomic, assign) float width; @property (nonatomic, assign) float height; @property (nonatomic, assign) float centerX; @property (nonatomic, assign) float centerY; @property (nonatomic, assign) CGSize size; @property (nonatomic, assign) CGPoint origin;
#pragma mark- set - (void) setOrigin:(CGPoint)origin { CGRect frame = self.frame; frame.origin = origin; self.frame = frame; } - (void) setX:(float)x { CGRect frame = self.frame; frame.origin.x = x; self.frame = frame; } - (void) setY:(float)y { CGRect frame = self.frame; frame.origin.y = y; self.frame = frame; } - (void) setWidth:(float)width { CGRect frame = self.frame; frame.size.width = width; self.frame = frame; } - (void) setHeight:(float)height { CGRect frame = self.frame; frame.size.height = height; self.frame = frame; } - (void) setSize:(CGSize)size { CGRect frame = self.frame; frame.size = size; self.frame = frame; } - (void)setCenterX:(float)centerX { CGPoint center = self.center; center.x = centerX; self.center = center; } - (void) setCenterY:(float)centerY { CGPoint center = self.center; center.y = centerY; self.center = center; } #pragma mark- get - (float)centerX { return self.center.x; } - (float)centerY { return self.center.y; } -(CGPoint)origin { return self.frame.origin; } - (float)height { return self.frame.size.height; } - (float)width { return self.frame.size.width; } - (CGSize)size { return self.frame.size; } - (float)x { return self.frame.origin.x; } - (float)y { return self.frame.origin.y; }