博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UILabel里字体带下划线
阅读量:6958 次
发布时间:2019-06-27

本文共 1002 字,大约阅读时间需要 3 分钟。

- (void)drawRect:(CGRect)rect
 
{
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    const CGFloat* colors = CGColorGetComponents(self.textColor.CGColor);
    
    CGContextSetRGBStrokeColor(ctx, colors[0], colors[1], colors[2], 1.0); // RGBA
    
    CGContextSetLineWidth(ctx, 1.0f);
    CGSize tmpSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(self.frame.size.width, 9999)];
    
    int height = tmpSize.height;
    
    int lineHeight = self.font.pointSize+4;
    
    int maxCount = height/lineHeight;
    
    float totalWidth = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(1000, 9999)].width;
    
    for(int i=1;i<=maxCount;i++)
        
    {
        
        float width=0.0;
        if((i*self.frame.size.width-totalWidth)<=0)
            width = self.frame.size.width;
        else
            width = self.frame.size.width - (i* self.frame.size.width - totalWidth);
        CGContextMoveToPoint(ctx, 0, lineHeight*i-1);
        CGContextAddLineToPoint(ctx, width, lineHeight*i-1);
    }
    
    CGContextStrokePath(ctx);
    
    [super drawRect:rect];
}

转载于:https://www.cnblogs.com/greywolf/archive/2012/12/28/2837050.html

你可能感兴趣的文章
为什么 SQLite 用 C 编写?
查看>>
送给@吴迪 的话,也是送给大家的话!
查看>>
用CMD开启Windows下的服务命令
查看>>
Explain吧!MySQL
查看>>
4.1 df命令 4.2 du命令 4.3-4.4 磁盘分区(上)(下)
查看>>
百度logo帧图使用
查看>>
条码系统与ERP交互
查看>>
在Dubbo中开发REST风格的远程调用(RESTful Remoting)
查看>>
eclipse导入远程git代码及(push、pull、及maven工程导入)
查看>>
openstack ice自定义调度算法项目详解(horizon、novaclient、api、scheduler、db、自定义数据库)...
查看>>
亿级订单同步
查看>>
hibernate.current_session_context_class
查看>>
cropper图片裁剪上传
查看>>
Redis服务端集群配置
查看>>
Spring框架JdbcTemplate类中查询方法介绍
查看>>
babel 6.0 在线测试
查看>>
CG行业的一个重要成员——广告
查看>>
PHP基础知识
查看>>
Apache相关配置记录
查看>>
Android RecyclerView 使用完全解析 体验艺术般的控件
查看>>