今天遇到了在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];
网友评论