国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iosUILabel加刪除線

2019-11-14 20:37:06
字體:
來源:轉載
供稿:網友

首先生成一個繼承與UILabel的類SFPStrikeThroughAndUnderLineLabel

一,在.h文件里

@interface SFPStrikeThroughAndUnderLineLabel : UILabel

{

    BOOL _isWithStrikeThrough;   

}

 @PRoperty (nonatomic, assign) BOOL isWithStrikeThrough; //控制是否顯示刪除線

@property (nonatomic, assign) CGFloat strikeThroughLineWidth;//設置刪除線的寬度

@property (nonatomic, retain) NSArray *strikeThroughRGBAlphaArray;//設置刪除線的顏色,數組里面的元素分別是RGB以及alpha值也就是說該數組有四個元素

@end

二,在.m文件里

#import "SFPStrikeThroughAndUnderLineLabel.h"

 

@implementation SFPStrikeThroughAndUnderLineLabel

@synthesize isWithStrikeThrough = _isWithStrikeThrough;

@synthesize strikeThroughRGBAlphaArray = _strikeThroughRGBAlphaArray;

@synthesize strikeThroughLineWidth = _strikeThroughLineWidth;

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

        

        self.strikeThroughRGBAlphaArray = [[NSArrayalloc]initWithObjects:@"0",@"0",@"0",@"1", nil];//默認刪除線的顏色是黑色切實不透明的,給個默認值,建立對象時該屬性可以不必賦值

        self.strikeThroughLineWidth = 1;//默認刪除線的寬度是1pix

        

        

    }

    returnself;

}

 

 

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

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

    // Drawing code

    

    if (self.isWithStrikeThrough)//顯示刪除線

    {

        CGContextRef c = UIGraphicsGetCurrentContext();

        

        CGFloat color[4] = {[[self.strikeThroughRGBAlphaArrayobjectAtIndex:0] floatValue], [[self.strikeThroughRGBAlphaArrayobjectAtIndex:1] floatValue], [[self.strikeThroughRGBAlphaArrayobjectAtIndex:2] floatValue], [[self.strikeThroughRGBAlphaArrayobjectAtIndex:3] floatValue]};

        CGContextSetStrokeColor(c, color);

        CGContextSetLineWidth(c, self.strikeThroughLineWidth);

        CGContextBeginPath(c);

        CGFloat halfWayUp = (self.bounds.size.height - self.bounds.origin.y) / 2.0;

        CGContextMoveToPoint(c, self.bounds.origin.x, halfWayUp );

        CGContextAddLineToPoint(c, self.bounds.origin.x + self.bounds.size.width, halfWayUp);

        CGContextStrokePath(c);

    }

    [super drawRect:rect];

}

三,使用:添加SFPStrikeThroughAndUnderLineLabel.h文件

 SFPStrikeThroughAndUnderLineLabel *oneLabel = [[SFPStrikeThroughAndUnderLineLabelalloc]initWithFrame:CGRectMake(20, 20, 100, 200)];

    oneLabel.backgroundColor = [UIColorwhiteColor];

    oneLabel.numberOfLines = 0;

    oneLabel.text = @"朱冬玲,我愛你一萬年;朱冬玲,我愛你一萬年;朱冬玲,我愛你一萬年;朱冬玲,我愛你一萬年;朱冬玲,我愛你一萬年";

    oneLabel.isWithStrikeThrough = YES;

//    下面這兩個屬性可設可不設值,他們設的都有默認值

//    oneLabel.rgbAlphaArray = [NSArray arrayWithObjects:@"255",@"255",@"0",@"1", nil];

//    oneLabel.strikeThroughLineWidth = 20;

    [self.view addSubview:oneLabel];

注意:這是給UILabel整個控件加刪除線(一個label只會有一條刪除線),而不是給label的text加刪除線 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铅山县| 安庆市| 咸丰县| 城口县| 秦安县| 江山市| 北京市| 丁青县| 甘洛县| 阿克苏市| 永兴县| 会泽县| 如东县| 彰武县| 平潭县| 奉化市| 大名县| 乌拉特后旗| 万州区| 荆州市| 徐闻县| 青海省| 报价| 眉山市| 河东区| 依安县| 四川省| 榕江县| 普定县| 昆明市| 禹城市| 清远市| 灵台县| 彭泽县| 灵石县| 庆云县| 商丘市| 太谷县| 修水县| 光泽县| 太仆寺旗|