当前位置:   article > 正文

带下划线,中滑线,下划线的lable

ui 设计中的中滑线是什么意思

typedef enum{

    

    LineTypeNone,//没有画线

    LineTypeUp ,// 上边画线

    LineTypeMiddle,//中间画线

    LineTypeDown,//下边画线

    

} LineType ;


@interface QFLineLabel : UILabel

//样式

@property (assign, nonatomic) LineType lineType;

//颜色

@property (assign, nonatomic) UIColor * lineColor;



@end

#import "QFLineLabel.h"


@implementation QFLineLabel


- (void)dealloc{

    

    self.lineColor = nil;

   

}

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

    }

    return self;

}


/*

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

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

    // Drawing code

}

*/

- (void)drawTextInRect:(CGRect)rect{

    [super drawTextInRect:rect];

    //文字宽度

    CGSize textSize = [[self text] sizeWithFont:[self font]];

    CGFloat strikeWidth = textSize.width;

    CGRect lineRect;

    CGFloat origin_x;

    CGFloat origin_y;

    

    if ([self textAlignment] == NSTextAlignmentRight) {

        

        origin_x = rect.size.width - strikeWidth;

        

    } else if ([self textAlignment] == NSTextAlignmentCenter) {

        

        origin_x = (rect.size.width - strikeWidth)/2 ;

        

    } else {

        

        origin_x = 0;

    }

    

    

    if (self.lineType == LineTypeUp) {

        

        origin_y =  2;

    }

    

    if (self.lineType == LineTypeMiddle) {

        

        origin_y =  rect.size.height/2;

    }

    

    if (self.lineType == LineTypeDown) {//下画线

        

        origin_y = rect.size.height - 2;

    }

    

    lineRect = CGRectMake(origin_x , origin_y, strikeWidth, 1);

    

    if (self.lineType != LineTypeNone) {

        

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGFloat R, G, B, A;

        UIColor *uiColor = self.lineColor;

        CGColorRef color = [uiColor CGColor];

        int numComponents = CGColorGetNumberOfComponents(color);

        

        if( numComponents == 4)

        {

            const CGFloat *components = CGColorGetComponents(color);

            R = components[0];

            G = components[1];

            B = components[2];

            A = components[3];

            CGContextSetRGBFillColor(context, R, G, B, 1.0);


        }

        //填充矩形

        CGContextFillRect(context, lineRect);

        

    }

}





@end


转载于:https://my.oschina.net/zhuzhu1223/blog/415901

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/729111
推荐阅读
相关标签
  

闽ICP备14008679号