本系列博客是本人的開發筆記。爲了方便討論,本人新建了一個微信羣(iOS技術討論羣),想要加入的,請添加本人微信:zhujinhui207407,【加我前請備註:iOS 】,本人博客http://www.kyson.cn 也在不停的更新中,歡迎一起討論
背景
+(NSAttributedString *)grabStatusString {
NSMutableAttributedString *attri2 = [[NSMutableAttributedString alloc] init];
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
attch.image = [UIImage imageNamed:@"ic_grab_gou_green"];
attch.bounds = CGRectMake(1, 1, attch.image.size.width * 1.1, attch.image.size.height * 1.1);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri2 insertAttributedString:string atIndex:0];
//文字
NSDictionary *style1 = [LPDAppStyle attributesWithFont:FONT(11) color:COLOR(FFF)];
NSMutableDictionary *resultStyle = [NSMutableDictionary dictionaryWithDictionary:style1];
NSString *statusText = @" 已取餐";
NSAttributedString *statusAttriString = [[NSAttributedString alloc] initWithString:statusText attributes:resultStyle];
[attri2 appendAttributedString:statusAttriString];
return attri2;
}
以及
-(void)drawTextInRect:(CGRect)rect {
// inset 的意思 是相對u於以前的,以前相對於各個方向是0,那麼如果想要改變,則需要 加 或者減
UIEdgeInsets insets = {-1, 2, 2, 2};
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}