zoukankan      html  css  js  c++  java
  • iOS

    //创建富文本
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@" -积分商城-热门商品-优惠券,后续会陆续打通东方明珠塔等各类上海文化消费优惠券。"];
        //NSTextAttachment可以将要插入的图片作为特殊字符处理
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        //定义图片内容及位置和大小
        attch.image = [UIImage imageNamed:@"home_profile_icon"];
        attch.bounds = CGRectMake(0, 0, 15, 15);
        //创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        
        //将图片放在最后一位
        //[attri appendAttributedString:string];
        //将图片放在第一位
        [attri insertAttributedString:string atIndex:0];
        //用label的attributedText属性来使用富文本
        _imgLabel.attributedText = attri;
        
        //若想对图片添加点击事件,现在的想法是在label上添加一个透明按钮,位置大小跟图片的相同
        _imgLabel.userInteractionEnabled = YES;
        UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        clearBtn.frame = CGRectMake(0, 12, attch.bounds.size.width, attch.bounds.size.height+3);
        clearBtn.backgroundColor = [UIColor clearColor];
        [clearBtn addTarget:self action:@selector(alertSth) forControlEvents:UIControlEventTouchUpInside];
        [_imgLabel addSubview:clearBtn];
  • 相关阅读:
    合约广告系统-在线分配问题
    合约广告系统-合约广告系统
    合约广告系统-常用广告系统开源工具
    knnsearch
    ISOMAP和MDS降维
    dijstra算法
    矩阵大于某个数置零
    mathtype 公式分节隐藏
    fifo 实现问题
    vhdl 数据类型转换 使用IEEE标准库numeric_std 需要进行两次转换 use ieee.numeric_std.all;
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10534834.html
Copyright © 2011-2022 走看看