zoukankan      html  css  js  c++  java
  • UIButton 上的标题添加下划线效果

    subclass UIButton类 重载drawrect方法:

    - (void)drawRect:(CGRect)rect 
        {
                // Get the Render Context
            CGContextRef ctx = UIGraphicsGetCurrentContext();
    
            // Measure the font size, so the line fits the text.
            // Could be that "titleLabel" is something else in other classes like UILable, dont know.
            // So make sure you fix it here if you are enhancing UILabel or something else..
            CGSize fontSize =[self.titleLabel.text sizeWithFont:self.titleLabel.font 
                                                       forWidth:self.bounds.size.width
                                                  lineBreakMode:UILineBreakModeTailTruncation];
            // Get the fonts color. 
            const float * colors = CGColorGetComponents(self.titleLabel.textColor.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)   
            float fontLeft = self.titleLabel.center.x - fontSize.width/2.0;
            float fontRight = self.titleLabel.center.x + fontSize.width/2.0;
    
            // Add Move Command to point the draw cursor to the starting point
            CGContextMoveToPoint(ctx, fontLeft, self.bounds.size.height - 1);
    
            // Add Command to draw a Line
            CGContextAddLineToPoint(ctx, fontRight, self.bounds.size.height - 1);
    
            // Actually draw the line.
            CGContextStrokePath(ctx);
    
            // should be nothing, but who knows...
            [super drawRect:rect];   
        }
  • 相关阅读:
    EBS SQL > Form & Report
    oracle sql 优化分析点
    MRP 物料需求计划
    MRPII 制造资源计划
    Barcode128 应用实务
    Oracle SQL语句优化技术分析
    APPSQLAP10710 Online accounting could not be created. AP Invoice 无法创建会计分录
    Oracle数据完整性和锁机制
    ORACLE Responsibility Menu Reference to Other User
    EBS 常用 SQL
  • 原文地址:https://www.cnblogs.com/kelisi-king/p/3290271.html
Copyright © 2011-2022 走看看