美文网首页
工作记录

工作记录

作者: wsdxsyb | 来源:发表于2016-05-27 17:35 被阅读14次

    今天遇到了在label和button下方划线的问题,请教了百度

    UILabel设置下划线:

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 310, 50)];

    label.backgroundColor = [UIColor redColor];

    [label setLineBreakMode:NSLineBreakByWordWrapping];

    label.numberOfLines =3;

    [label setFont:[UIFont systemFontOfSize:14]];

    NSMutableAttributedString*content = [[NSMutableAttributedStringalloc]initWithString:[NSStringstringWithFormat:@"博文地址:http://www.cnblogs.com/xiaofeixiang博客园-FlyElephant QQ群:228407086"]];

    NSRangecontentRange = {0,[content length]};

    [content addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle] range:contentRange];

    label.attributedText = content;

    [self.view addSubview:label];

    UIButton设置下划线:

    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(10, 200, 80, 30)];

    NSMutableAttributedString*title = [[NSMutableAttributedStringalloc] initWithString:@"FlyElephant"];

    NSRangetitleRange = {0,[title length]};

    [title addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle] range:titleRange];

    [button setAttributedTitle:title

    forState:UIControlStateNormal];

    [button setBackgroundColor:[UIColor redColor]];

    [button.titleLabel setFont:[UIFont systemFontOfSize:14]];

    [self.view addSubview:button];

    相关文章

      网友评论

          本文标题:工作记录

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