您好,登錄后才能下訂單哦!
//
// 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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。