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

  • 相关阅读:
    使用自定义RadioButton和ViewPager实现TabHost效果和带滑动的页卡效果
    Android 实现文件上传功能(upload)
    Hibernate配置文件
    ICMP报文分析
    AVC1与H264的差别
    内存泄漏以及常见的解决方法
    数据挖掘十大经典算法
    关于java的JIT知识
    Ubuntu安装二:在VM中安装Ubuntu
    hdu 1520Anniversary party(简单树形dp)
  • 原文地址:https://www.cnblogs.com/ldc529/p/3874887.html
Copyright © 2011-2022 走看看