pragma mark - 重画tableview的线
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
//下分割线
CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}
pragma mark - 如何给UILabel添加中线
UILabel * strikeLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [NSString stringWithFormat:@"%@元", primeCost];
//中划线
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
// 赋值
strikeLabel.attributedText = attribtStr;
[self.view addSubview:strikeLabel];
pragma mark - 如何给UILabel添加下划线
UILabel *underlineLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [NSString stringWithFormat:@"%@元", primeCost];
// 下划线
NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
//赋值
underlineLabel.attributedText = attribtStr;
[self.view addSubview:underlineLabel];
pragma mark - 创建Button下划线
UIButton *button = [[UIButtonalloc]initWithFrame:CGRectMake(0,0, KScreenWidth,25)];
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColorcolorWithRed:239.0/255.0green:152.0/255.0blue:121.0/255.0alpha:1]];
[button.titleLabel setFont:[UIFont systemFontOfSize:10]];
NSMutableAttributedString *title = [[NSMutableAttributedStringalloc] initWithString:@"号源紧俏经常预约不上?试试预约抢号功能? >>"];
NSRange titleRange = {0, [titlelength]};
[title addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:titleRange];
[button setAttributedTitle:titleforState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。