123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #import "UIView+Setter.h"
- @implementation UIView(Setter)
- -(void)boardWid:(CGFloat)wid Color:(UIColor*)col
- {
- self.layer.borderColor = col.CGColor;
- self.layer.borderWidth = wid;
- }
- -(void)corner:(CGFloat)cor
- {
- self.layer.cornerRadius = cor;
- self.layer.masksToBounds = YES;
- }
- -(void)scale:(CGFloat)rate
- {//CGAffineTransformIdentity
- // self.transform = CGAffineTransformScale(self.transform, rate,rate);
- self.transform = CGAffineTransformScale(CGAffineTransformIdentity, rate,rate);
- }
- -(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:lineColor];
- }
- -(void)addSelfViewWithRect:(CGRect)re
- {
- UIView *v = [[UIView alloc] initWithFrame:re];
- [v setBackgroundColor:lineColor];
- [self addSubview:v];
- }
- @end
- @implementation UIViewController(Setter)
- -(void)configNavBar
- {
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
- [backBbi setTintColor:defGreen];
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- -(void)goBack{
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)configNavigationBarDismissNav
- {
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNav)];
- [backBbi setTintColor:defGreen];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- -(void)dismissNav
- {
- [self.view endEditing:YES];
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- }
- -(void)addV:(UIView*)aView
- {
- [self.view addSubview:aView];
- }
- @end
- @implementation UIImageView(Setter)
- -(void)imageName:(NSString*)name
- {
- [self setImage:[UIImage imageNamed:name]];
- }
- @end
- @implementation UIButton(Setter)
- - (void) setPersonalImage:(UIImage *)img Tit:(NSString *)tit Font:(CGFloat)font State:(UIControlState)state
- {
- [self.titleLabel setContentMode:UIViewContentModeCenter];
- [self setTitleColor:[UIColor whiteColor] forState:state];
- [self setTitle:tit forState:state];
- [self.titleLabel setFont:[UIFont scaleSize:font]];
-
- [self setImage:img forState:state];
- [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
-
- //文字图片位置调整
- self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- // self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- //适应字体及内容,否则titleLabel的尺寸为(0,0)
- [self.titleLabel sizeToFit];
- //设置图标四周边界
- [self setImageEdgeInsets:UIEdgeInsetsMake(10, 0, 10, 20)];
- //设置标题四周边界
- [self setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
-
- [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
- }
- - (void) setImage:(UIImage *)img Tit:(NSString *)tit Font:(CGFloat)font State:(UIControlState)state
- {
- [self.titleLabel setContentMode:UIViewContentModeCenter];
- [self setTitleColor:titleColor forState:state];
- [self setTitle:tit forState:state];
- [self.titleLabel setFont:[UIFont scaleSize:font]];
-
- [self setImage:img forState:state];
- [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
- }
- -(void) setTitle:(NSString*)title textColor:(UIColor*)color font:(CGFloat)font fotState:(UIControlState)stateType
- {
- [self setTitle:title forState:stateType];
- [self setTitleColor:color forState:stateType];
- [self.titleLabel setFont:[UIFont scaleSize:font]];
- //scaleSize
- }
- -(void)target:(id)obj
- {
- [self addTarget:obj action:NSSelectorFromString(@"btnClick:") forControlEvents:UIControlEventTouchUpInside];
- }
- -(void)target:(id)obj Tag:(NSInteger)tag
- {
- [self target:obj];
- [self setTag:tag];
- }
- @end
- @implementation UILabel(Setter)
- -(void)setFont:(CGFloat)font TextColor:(UIColor*)color
- {
- [self setFont:[UIFont scaleSize:font]];
- [self setTextColor:color];
- }
- -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color
- {
- [self setText:text];
- [self setFont:[UIFont scaleSize:font]];
- [self setTextColor:color];
- }
- -(void)setText:(NSString*)text Font:(CGFloat)font TextColor:(UIColor*)color Alignment:(NSTextAlignment)align
- {
- [self setText:text Font:font TextColor:color];
- [self setTextAlignment:align];
- }
- -(void)boardWid:(CGFloat)wid Color:(UIColor*)col
- {
- self.layer.borderColor = col.CGColor;
- self.layer.borderWidth = wid;
- }
- -(void)corner:(CGFloat)cor
- {
- self.layer.cornerRadius = cor;
- self.layer.masksToBounds = YES;
- }
- @end
- void SetRandomColor(UIView* vi)
- {
- UIColor *color = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0];
- [vi setBackgroundColor:color];
- }
- void SetRandomColorS(UIView* vi)
- {
- for (UIView* v in vi.subviews) {
- SetRandomColor(v);
- }
- }
|