p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC" }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC"; min-height: 17.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #e82300 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; min-height: 13.0px }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #36568a }
p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #36568a; min-height: 13.0px }
p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #587ea8 }
span.s1 { color: #777897 }
span.s2 { }
span.s3 { color: #36568a }
span.s4 { color: #c35900 }
span.s5 { font: 11.0px Menlo; color: #36568a }
span.s6 { color: #000000 }
span.s7 { color: #587ea8 }
做项目经常遇到一个问题,给Button增加一个高亮状态,如果公司有ui还好,可以让ui给你切个高度状态的图片,没有ui只能自己切图或给按钮添加背景颜色,但是这个处理起来有没麻烦,并且一个项目不过能只有那么一个button需要添加这个状态颜色,所以自己也常试封装一个button的背景颜色,上代码,如果哪位大神有好的建议也希望能告诉我,直接留言,谢谢
//这是继承UIButton的扩展类
//UIButton+MHFillColor.h
#import <UIKit/UIKit.h>
@interface UIButton (MHFillColor)
- (void)ym_setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state;
@end
//UIButton+MHFillColor.m
#import "UIButton+MHFillColor.h"
@implementation UIButton (MHFillColor)
- (void)ym_setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
[self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end