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

    #import <Foundation/Foundation.h>
    @interface UnderlineUILabel : UILabel 
    {

    }

    @end

    #import "UnderlineUILabel.h"
    #import<QuartzCore/QuartzCore.h>

    @implementation UnderlineUILabel

    -(id)initWithFrame:(CGRect)frame
    {
    if(self = [super initWithFrame:frame])
    {
    }
    return self;
    }
    -(void)drawRect:(CGRect)rect 
    {
    [super drawRect:rect];
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGSize fontSize =[self.text sizeWithFont:self.font 
           forWidth:self.bounds.size.width
           lineBreakMode:UILineBreakModeTailTruncation];


           
    // Get the fonts color. 
    const float * colors = CGColorGetComponents([UIColor blueColor].CGColor);
    // Sets the color to draw the line
    CGContextSetRGBStrokeColor(ctx, colors[0], colors[1], colors[2], 1.0f); // Format : RGBA

    // Line Width : make thinner or bigger if you want
    CGContextSetLineWidth(ctx, 1.0f);

    // Calculate the starting point (left) and target (right)
    CGPoint l = CGPointMake(self.frame.size.width/2.0 - fontSize.width/2.0, 
              self.frame.size.height/2.0 +fontSize.height/2.0);
    CGPoint r = CGPointMake(self.frame.size.width/2.0 + fontSize.width/2.0, 
             self.frame.size.height/2.0 + fontSize.height/2.0);


    // Add Move Command to point the draw cursor to the starting point
    CGContextMoveToPoint(ctx, l.x, l.y);

    // Add Command to draw a Line
    CGContextAddLineToPoint(ctx, r.x, r.y);


    // Actually draw the line.
    CGContextStrokePath(ctx);

    // should be nothing, but who knows...
    [super drawRect:rect];   
    }

    @end

  • 相关阅读:
    c++类中的常量
    什么是租赁
    期末结转销售成本结算利润
    合并报表抵消分录借:营业成本 贷:存货怎么理解(自己分析)
    电脑上装安卓系统
    下载apps from google play on windows 10
    virtualbox找不到ubuntu64选项
    如何区分其他综合收益和当期损益
    哪些项目进其他综合收益
    境外经营财务报表的折算方法
  • 原文地址:https://www.cnblogs.com/greywolf/p/2837556.html
Copyright © 2011-2022 走看看