您好,登录后才能下订单哦!
//
// BtnControl.m
// ZCar
//
// Created by imac on 15/10/4.
// Copyright (c) 2015年 imac. All rights reserved.
//
#import "BtnControl.h"
@implementation BtnControl
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.layer.borderWidth = 1;
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
-(void)setNameWithTitle:(NSString *)nameWithTitle
{
if (_nameWithTitle != nameWithTitle) {
_nameWithTitle = nameWithTitle;
[self setNeedsDisplay];
}
}
- (void)setImgName:(NSString *)imgName
{
if (_imgName != imgName) {
_imgName = imgName;
[self setNeedsDisplay];
}
}
- (void)setDic:(NSDictionary *)dic
{
if (_dic != dic) {
_dic = dic;
[self setNeedsDisplay];
}
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
[self drawWithText:_nameWithTitle ImgName:_imgName titleColor:_dic];
}
- (void)drawWithText:(NSString *)title ImgName:(NSString *)imgName titleColor:(NSDictionary *)dic{
UIImage *img = [UIImage p_w_picpathNamed:imgName];
[img drawInRect:CGRectMake(self.width - 27, self.height - 12, 25, 10)];
int i = [self convertToInt:title];
float width = (self.width - i * 12) / 2;
[title drawInRect:CGRectMake(width, 10, self.width, self.height) withAttributes:dic];
}
- (int)convertToInt:(NSString*)strtemp {
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
if (*p) {
p++;
strlength ++;
}
else {
p ++;
}
}
return (strlength + 1) / 2;
}
@end
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。