zoukankan      html  css  js  c++  java
  • 下划线按钮

    #import <UIKit/UIKit.h>

    @interface CXUnderLineButton : UIButton

    + (CXUnderLineButton *) underlinedButton;

    @end

    #import "CXUnderLineButton.h"

    @implementation CXUnderLineButton

    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

        }

        return self;

    }

    + (CXUnderLineButton*) underlinedButton {

        CXUnderLineButton* button = [[CXUnderLineButton alloc] init];

        return button;

    }

    - (void) drawRect:(CGRect)rect {

        CGRect textRect = self.titleLabel.frame;

        

        // need to put the line at top of descenders (negative value)

        CGFloat descender = self.titleLabel.font.descender;

        

        CGContextRef contextRef = UIGraphicsGetCurrentContext();

        

        // set to same colour as text

        CGFloat offset = 1.f;

        CGContextSetStrokeColorWithColor(contextRef, self.highlighted?[UIColor grayColor].CGColor: self.titleLabel.textColor.CGColor);

        

        CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender + offset);

        

        CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender + offset);

        

        CGContextClosePath(contextRef);

        

        CGContextDrawPath(contextRef, kCGPathStroke); 

    /*

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect

    {

        // Drawing code

    }

    */

    @end

  • 相关阅读:
    JUC锁框架_AbstractQueuedSynchronizer详细分析
    npm的镜像替换成淘宝
    MHA+keepalived集群环境搭建
    Java并发编程:CountDownLatch、CyclicBarrier和Semaphore
    链表中倒数第k个结点
    调整数组顺序使奇数位于偶数前面
    数值的整数次方
    二进制中1的个数
    矩形覆盖
    OS之进程管理---多线程模型和线程库(POSIX PTread)
  • 原文地址:https://www.cnblogs.com/ldc529/p/3874887.html
Copyright © 2011-2022 走看看