美文网首页
iOS原价划线

iOS原价划线

作者: ace_xuke | 来源:发表于2017-12-21 18:50 被阅读0次

第一种:

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
image.png
image.png

over!

相关文章

网友评论

      本文标题:iOS原价划线

      本文链接:https://www.haomeiwen.com/subject/dioawxtx.html