TextKit

作者: Vijay_ | 来源:发表于2017-12-13 16:01 被阅读7次

    NSAttributedString


    • 图文混排(富文本)
    UILabel *label = [[UILabel alloc] init];
    
        NSMutableAttributedString *content = [[NSMutableAttributedString alloc] init];
        NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"hello" attributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
        [content appendAttributedString:first];
    
        //创建附件
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        //附件添加图片
        attachment.image = [UIImage imageNamed:@"header_cry_icon"];
        attachment.bounds = CGRectMake(0, 0, label.font.lineHeight, label.font.lineHeight);
        NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
        //加入富文本中
        [content appendAttributedString:attachmentString];
    
    
        NSAttributedString *thired = [[NSAttributedString alloc] initWithString:@"你好" attributes:@{NSForegroundColorAttributeName:[UIColor purpleColor]}];
        [content appendAttributedString:thired];
    
    
        label.attributedText = content;
        label.frame = CGRectMake(100, 100, 200, 100);
        [self.view addSubview:label];
    

    相关文章

      网友评论

          本文标题:TextKit

          本文链接:https://www.haomeiwen.com/subject/ogfzixtx.html