今天遇到了在label和button下方劃線的問題总处,請(qǐng)教了百度
UILabel設(shè)置下劃線:
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設(shè)置下劃線:
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];