富文本-图文混排

摘要:
混合图像和文本//混合图像和文字NSMutableAttributedString*attributedText=[[NSMutabbleAttributedStringalloc]init]//1-Hello NSAttributedString*first=[[NSattributeStringalloc]init WithString:@“Hello”];[attributedTextappendAttributed

图文混排

    // 图文混排
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] init];
    // 1 - 你好
    NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"你好"];
    [attributedText appendAttributedString:first];

    // 2 - 图片
    // 带有图片的附件对象
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    attachment.image = [UIImage imageNamed:@"header_cry_icon"];
    CGFloat lineH = label.font.lineHeight;
    attachment.bounds = CGRectMake(0, - ((label.xmg_height - lineH) * 0.5 - 1), lineH, lineH);
    // 将附件对象包装成一个属性文字
    NSAttributedString *second = [NSAttributedString attributedStringWithAttachment:attachment];
    [attributedText appendAttributedString:second];

    // 3 - 哈哈哈
    NSAttributedString *third = [[NSAttributedString alloc] initWithString:@"哈哈哈"];
    [attributedText appendAttributedString:third];

    label.attributedText = attributedText;

结果展示

  UILabel *label = [[UILabel alloc] init];
  //    label.text = @"你好哈哈哈";
    NSMutableAttributedString *text =    [[NSMutableAttributedString alloc] initWithString:@"你好哈哈哈"];
    [text addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, 3)];
    [text addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 3)];
    label.attributedText = text;
    label.frame = CGRectMake(100, 100, 100, 25);
    [self.view addSubview:label];

结果展示

    UILabel *label = [[UILabel alloc] init];
    // 设置属性文字
    NSString *text = @"你好
哈哈哈";
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
    [attributedText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:10] range:NSMakeRange(0, text.length)];
    [attributedText addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13] range:NSMakeRange(3, 3)];
    label.attributedText = attributedText;
    // 其他设置
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.frame = CGRectMake(0, 0, 100, 40);
    [self.view addSubview:label];
    self.navigationItem.titleView = label;

结果展示

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CentOS 7运维管理笔记(6)----Apache 基于 IP 的虚拟主机配置Oracle写函数读写日志实例下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

如何利用添加伪元素的办法自定义checkbox以及radio选框的样式

这里我以checkbox举例(radio同理),上图为默认样式 这是我修改之后的样式 直接进入主题吧 首先在我们的vs里面输入如上代码 键入一个input框,类型为checkbox 再写一个label,给for属性赋予checkbox的ID值,让两个产生联动 这样,我们点击label里面的内容的时候,可以让checkbox选中 然后我们给label新...

ios 设置label的高度随着内容的变化而变化

好吧  步骤1:创建label _GeRenJianJie = [[UILabel alloc]init]; 步骤2:设置label _GeRenJianJie.textColor = RGBAColor(95, 104, 115, 1); _GeRenJianJie.numberOfLines = 0; // 需要把显示行数设置成无限制...

Qt---ToolBox自由伸展

参考:Qt实战12.可自由展开的ToolBox - Qt小罗 - 博客园 (cnblogs.com)   1 MainWindow::MainWindow(QWidget *parent) 2 : QMainWindow(parent) 3 , ui(new Ui::MainWindow) 4 { 5 ui->set...

【转】C# WinForm中的Label如何换行

        第一种是把Label的AutoSize属性设为False,手动修改Label的大小.这样的好处是会因内容的长度而自动换行,但是当内容的长度超过所设定的大小时,多出的内容就会无法显示.因此,这种方法适合于基本确定内容长度的时候使用.         第二种是把Label的Dock设为FILL,同时将AutoSize属性设为False,这种方法...

G2使用中的一些坑:自定义图例、混合图形、label 默认隐藏等问题

一、自定义图例 legend 一般自定义图例较多的使用在混合图形里,以 G2 官网的这个 chart 为例,通过定制 legend 来显示自己定义的图例。 注意:legend 的配置项里一定要设置 custom: true ,自己在写的时候过多关注多个图形叠加使用,没有注意设置 custom,结果图表显示一直有问题,图例也显示不出来,折腾到怀疑人生。 二...

【学习笔记】tensorflow图片读取

目录 图像基本概念 图像基本操作图像基本操作API 图像读取API 狗图片读取 CIFAR-10二进制数据读取 TFRecords TFRecords存储 TFRecords读取方法 图像基本概念 在图像数字化表示当中,分为黑白和彩色两种。在数字化表示图片的时候,有三个因素。分别是图片的长、图片的宽、图片的颜色通道数。那么黑白图片的颜色...