zoukankan      html  css  js  c++  java
  • UILabel里字体带下划线

    - (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];
    }
  • 相关阅读:
    CPU飙高,OOM排查?
    反射
    Mybatits
    spring 基础问题
    java中格式化数字0和#区别
    java中File对象的mkdir和mkdirs的区别
    java截取字符串几种方式
    java工厂模式
    Java获取文件路径的几种方式
    jxl生成excel时,增加批注和冻结窗口
  • 原文地址:https://www.cnblogs.com/greywolf/p/2837050.html
Copyright © 2011-2022 走看看