美文网首页iOS 成长之路iOS开发-绘制
iOS UILabel中底线、Button底线以及UITable

iOS UILabel中底线、Button底线以及UITable

作者: 奋拓达 | 来源:发表于2018-07-02 17:21 被阅读7次

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];

相关文章

  • iOS UILabel中底线、Button底线以及UITable

    pragma mark - 重画tableview的线 pragma mark - 如何给UILabel添加中线 ...

  • Android03-常见控件的使用

    TextView 类似于iOS的UILabel Button 显示一个button 给button绑定点击事件方式...

  • Button中UILabel和UIImage的布局

    Button中UILabel和UIImage的布局 要想很好的完成Button中UILabel和UIImage的布...

  • 底线思维

    工作和生活中我们要培养底线思维,做这个事情的底线是什么,低于这个底线是一定不能做的。 例如经营中每一项指标的底线是...

  • 反思的结果

    1.婚前没有讲好各自的底线,以至于婚后彼此试探触及对方底线。 2.婚姻生活中没有做到相互宽容,体谅以及及时的沟通。...

  • 底线是什么

    底线是什么? 底线是不能碰的尊严,底线是不能丢的骄傲,底线是不能跪的膝盖! 底线是什么?底线是生活的准则;底线是做...

  • 商业导师营没底线到处都是坑!

    底线、底线,做人要有底线。在五维商业导师营,人的极限没底线了,在这里“廖天师”打破我认知中记忆极限,演讲极限,成长...

  • iOS bug 记录

    1、自定义UIButton,自定义button中添加UIImageView和UILabel。设置button的en...

  • 你这个人做人还有没有底线?

    底线这个词,可用到各种情景下。 比如婚姻,你在婚姻中要求伴侣的底线是什么?要求自己的底线是什么?要求伴侣的底线是精...

  • 什么时是底线?(经典)

    什么是底线? 底线是不能触碰的尊严, 底线是不能失去的傲骨, 底线是不能跪下的膝盖! 什么是底线? 底线是做人的准...

网友评论

    本文标题:iOS UILabel中底线、Button底线以及UITable

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