您的位置:首页 > 产品设计 > UI/UE

UILable换行底部增加图片

2016-01-25 13:38 465 查看


UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, Width, 100)];
lable.numberOfLines=0;
[self.view addSubview:lable];

NSAttributedString *subStr1 = [[NSAttributedString alloc] initWithString:@"好傻好傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和撒谎莎莎婚纱"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont systemFontOfSize:15]
}];
NSAttributedString *subStr2 = [[NSAttributedString alloc] initWithString:@"哈哈哈哈哈哈哈"
attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],
NSFontAttributeName:[UIFont systemFontOfSize:15]
}];

NSTextAttachment *attch = [[NSTextAttachment alloc] init];
attch.image=[UIImage imageNamed:@"error"];
attch.bounds=CGRectMake(0, -3, [UIFont systemFontOfSize:15].lineHeight, [UIFont systemFontOfSize:15].lineHeight);

NSAttributedString *subStr3 = [NSAttributedString attributedStringWithAttachment:attch];

NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] init];
[attrText appendAttributedString:subStr1];
[attrText appendAttributedString:subStr2];
[attrText appendAttributedString:subStr3];

lable.attributedText=attrText;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: