| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // StrikethroughLabel.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-5-29.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "StrikethroughLabel.h"
- #import "RAUtils.h"
- @implementation StrikethroughLabel
- - (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
- {
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- // CGRect frame = self.contentView.frame;
-
- // CGContextAddRect(context,frame);
- CGContextSetLineWidth(context, 0.5);
-
-
- // CGSize sizekey = [self.text sizeWithFont:self.font constrainedToSize:self.frame.size lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizekey = [RAUtils sizeWithFont:self.text font:self.font constrainedToSize:self.frame.size lineBreakMode:NSLineBreakByWordWrapping];
-
- // double width = sizekey.width*1.1;
- //
- // if(width>self.frame.size.width)
- // width = self.frame.size.width;
-
-
-
- CGContextSetStrokeColorWithColor(context, [self.textColor CGColor]);
-
- // CGRect selrect = self.bounds;
- // NSTextAlignmentLeft = 0, // Visually left aligned
- //#if TARGET_OS_IPHONE
- // NSTextAlignmentCenter = 1, // Visually centered
- // NSTextAlignmentRight = 2, // Visually right aligned
- //#else /* !TARGET_OS_IPHONE */
- // NSTextAlignmentRight = 1, // Visually right aligned
- // NSTextAlignmentCenter = 2, // Visually centered
- //#endif
- // NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
- // NSTextAlignmentNatural = 4,
- //
-
- switch(self.textAlignment)
- {
- case NSTextAlignmentLeft:
- CGContextMoveToPoint(context, 0, self.bounds.size.height/2);
-
- CGContextAddLineToPoint(context, sizekey.width, self.bounds.size.height/2);
- break;
- case NSTextAlignmentCenter:
- CGContextMoveToPoint(context, self.bounds.size.width/2 - (sizekey.width/2*1.15), self.bounds.size.height/2);
-
- CGContextAddLineToPoint(context, self.bounds.size.width/2 + (sizekey.width/2*1.15), self.bounds.size.height/2);
- break;
-
- case NSTextAlignmentRight:
- CGContextMoveToPoint(context, self.bounds.size.width, self.bounds.size.height/2);
-
- CGContextAddLineToPoint(context, self.bounds.size.width-sizekey.width, self.bounds.size.height/2);
- break;
- default:
- CGContextMoveToPoint(context, 0, self.bounds.size.height/2);
-
- CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height/2);
- }
-
-
- // CGContextStrokePath(context);
-
- // CGContextMoveToPoint(context, 0.5, self.bounds.origin.y);
- //
- // CGContextAddLineToPoint(context, 0.5, self.bounds.size.height);
- //
- //
- // CGContextMoveToPoint(context, self.bounds.size.width-0.5, self.bounds.origin.y);
- //
- // CGContextAddLineToPoint(context, self.bounds.size.width-0.5, self.bounds.size.height);
-
- if(!self.hideline)
- CGContextStrokePath(context);
-
- [super drawRect:rect];
- }
- @end
|