1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // UIButton+ex.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/13.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "UIButton+ex.h"
- @implementation UIButton (ex)
- -(void)setTitleUnderImgWithTitle:(NSString *)title TitleColor:(UIColor *)color Image:(UIImage *)image label:(UILabel *)topLab{
-
- CGFloat width = self.frame.size.width;
- CGFloat height = self.frame.size.height/10;
- CGRect topFrame = CGRectMake(width/2-height*4/2, height*2, height*4, height*4);
- if (image) {
- //图片+文字
- UIImageView * imgV = [[UIImageView alloc]initWithFrame:topFrame];
- imgV.image = image;
- [self addSubview:imgV];
-
- self.layer.borderWidth = .5f;
- self.layer.borderColor = [UIColor colorWithRed:230/255.0f green:230/255.0f blue:230/255.0f alpha:1].CGColor;
-
- }else{
- //lable+文字
- topLab.frame = topFrame;
- topLab.font = [UIFont systemFontOfSize:[self scaleFontSize:16]];
- topLab.adjustsFontSizeToFitWidth = YES;
- topLab.textColor = [UIColor darkGrayColor];
- topLab.textAlignment = NSTextAlignmentCenter;
- // topLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
-
- topLab.layer.borderWidth = .5f;
- topLab.layer.borderColor = [UIColor lightGrayColor].CGColor;
-
- topLab.layer.cornerRadius = 5;
- topLab.layer.masksToBounds = YES;
-
- [self addSubview:topLab];
-
- UILabel * Vline = [[UILabel alloc]initWithFrame:CGRectMake(width-1, height*2, 1, height*6)];
- Vline.backgroundColor = RGB_COLOR(230, 230, 230);
- [self addSubview:Vline];
-
- }
-
- UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, height*6, width, height*3)];
- lab.text = title;
- lab.textAlignment = NSTextAlignmentCenter;
- lab.textColor = [UIColor darkGrayColor];
- lab.font = [UIFont systemFontOfSize:[self scaleFontSize:14]];
- lab.numberOfLines = 2;//
- if (topLab) {
- lab.textColor = [UIColor grayColor];
- }
- [self addSubview:lab];
-
- }
- -(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 systemFontOfSize:font]];
- }
- -(CGFloat)scaleFontSize:(CGFloat)size{
-
- if (kSize.width < 414) {
- return size-1;
- }
- return size;
- }
- -(void)borderColor:(UIColor *)color width:(CGFloat)wid cornorRadios:(CGFloat)cornor
- {
- self.layer.masksToBounds = YES;
- self.layer.borderWidth = wid;
- self.layer.cornerRadius = cornor;
- self.layer.borderColor = color.CGColor;
- }
- @end
|