iOS中UILabel的深度定制

本系列博客是本人的开发笔记。为了方便讨论,本人新建了一个微信群(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)];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章