第一种:
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@",priceStirng] attributes:attribtDic];
self.priceLabel.attributedText =attribtStr;
第二种:
#import <UIKit/UIKit.h>
@interface KKCenterLineLabel : UILabel
@end
#import "KKCenterLineLabel.h"
@implementation KKCenterLineLabel
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
//第二种方法:
UIRectFill(CGRectMake(0, rect.size.height * 0.5, rect.size.width, 1));
/* 还可以这样
CGContextRef ctx = UIGraphicsGetCurrentContext();
//设置红色
// [[UIColor redColor]set];
//设置宽度
// CGContextSetLineWidth(ctx, 5);
//设置起点
CGContextMoveToPoint(ctx, 0, rect.size.height * 0.5);
//连接到另一个点
CGContextAddLineToPoint(ctx, rect.size.width, rect.size.height * 0.5);
//渲染
CGContextStrokePath(ctx);
*/
}
@end
over!