123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // UIView+Frame.m
- // WZLCodeLibrary
- //
- // Created by wzl on 15/3/23.
- // Copyright (c) 2015年 Weng-Zilin. All rights reserved.
- //
- #import "UIView+Frame.h"
- @implementation UIView (Frame)
- - (void)setX:(CGFloat)x
- {
- CGRect frame = self.frame;
- frame.origin.x = x;
- self.frame = frame;
- }
- - (CGFloat)x
- {
- return self.frame.origin.x;
- }
- - (void)setY:(CGFloat)y
- {
- CGRect frame = self.frame;
- frame.origin.y = y;
- self.frame = frame;
- }
- - (CGFloat)y
- {
- return self.frame.origin.y;
- }
- - (void)setOrigin:(CGPoint)origin
- {
- CGRect frame = self.frame;
- frame.origin = origin;
- self.frame = frame;
- }
- - (CGPoint)origin
- {
- return self.frame.origin;
- }
- - (void)setWidth:(CGFloat)width
- {
- CGRect frame = self.frame;
- frame.size.width = width;
- self.frame = frame;
- }
- - (CGFloat)width
- {
- return self.frame.size.width;
- }
- - (void)setHeight:(CGFloat)height
- {
- CGRect frame = self.frame;
- frame.size.height = height;
- self.frame = frame;
- }
- - (CGFloat)height
- {
- return self.frame.size.height;
- }
- - (void)setSize:(CGSize)size
- {
- CGRect frame = self.frame;
- frame.size = size;
- self.frame = frame;
- }
- - (CGSize)size
- {
- return self.frame.size;
- }
- - (void)setBottom:(CGFloat)bottom
- {
- CGRect frame = self.frame;
- frame.origin.y = bottom - frame.size.height;
- self.frame = frame;
- }
- - (CGFloat)bottom
- {
- return CGRectGetMaxY(self.frame);
- }
- - (CGFloat)tail
- {
- return CGRectGetMaxX(self.frame);
- }
- - (void)setTail:(CGFloat)tail
- {
- CGRect frame = self.frame;
- frame.origin.x = tail - frame.size.width;
- self.frame = frame;
- }
- - (void)setMiddleX:(CGFloat)middleX
- {
- CGRect frame = self.frame;
- frame.origin.x = middleX - frame.size.width / 2;
- self.frame = frame;
- }
- - (CGFloat)middleX
- {
- return CGRectGetMidX(self.frame);
- }
- - (void)setMiddleY:(CGFloat)middleY
- {
- CGRect frame = self.frame;
- frame.origin.y = middleY - frame.size.height / 2 ;
- self.frame = frame;
- }
- - (CGFloat)middleY
- {
- return CGRectGetMidY(self.frame);
- }
- @end
- @implementation UIView(formatter)
- -(void)setRound
- {
- self.layer.masksToBounds = YES;
- self.layer.cornerRadius = self.width/2.0;
- }
- -(void)boardWid:(CGFloat)width Color:(UIColor*)color
- {
- [self.layer setBorderWidth:width];
- [self.layer setBorderColor:color.CGColor];
- [self.layer setMasksToBounds:YES];
- [self.layer setCornerRadius:6];
- }
- -(void)borderCornorRadios:(CGFloat)cornor
- {
- self.layer.masksToBounds = YES;
- self.layer.cornerRadius = cornor;
- }
- -(void)borderColor:(UIColor *)color width:(CGFloat)wid cornorRadios:(CGFloat)cornor
- {
- self.layer.masksToBounds = YES;
- self.layer.cornerRadius = cornor;
- self.layer.borderWidth = wid;
- self.layer.borderColor = color.CGColor;
- }
- -(void)addViewWithRect:(CGRect)re Color:(UIColor*)color
- {
- UIView *v = [[UIView alloc] initWithFrame:re];
- [v setBackgroundColor:color];
- [self.superview addSubview:v];
- }
- -(void)addViewWithRect:(CGRect)re
- {
- [self addViewWithRect:re Color:kLineColor];
- }
- -(void)addSelfViewWithRect:(CGRect)re Color:(UIColor*)color
- {
- UIView *v = [[UIView alloc] initWithFrame:re];
- [v setBackgroundColor:color];
- [self addSubview:v];
- }
- -(void)scale:(CGFloat)rate
- {
- self.transform = CGAffineTransformScale(CGAffineTransformIdentity, rate,rate);
- }
- @end
|