iOS UILable的一些用法

1.按钮上的文字添加下划线

问题:实现下图中右侧的按钮文字效果

iOS UILable的一些用法

代码(绿色为按钮文字加下划线方法):

    [MyTools createMyImageview:topEditView frame:CGRectMake(widthAll-, , , ) imageName:@"离线课程_下载更多.png"];
UIButton *downMoreButton = [MyTools createMyBtn:@"下载更多" frame:CGRectMake(widthAll-, , , ) uiview:topEditView uifont: color:[UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:]];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"下载更多"];
NSRange titleRange = {0,[title length]};
[title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
[downMoreButton setAttributedTitle:title
forState:UIControlStateNormal];
[downMoreButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
[downMoreButton addTarget:self action:@selector(downMore) forControlEvents:UIControlEventTouchUpInside];

2.设置lable文字前后不同的颜色(参考:http://www.cocoachina.com/bbs/read.php?tid-282742-page-1.html

UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
timeLabel.font = [UIFont systemFontOfSize:];
timeLabel.textColor = [UIColor blackColor];
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"100:00/100:00"];
NSRange redRange = NSMakeRange(, [[noteStr string] rangeOfString:@"/"].location);
[noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
[timeLabel setAttributedText:noteStr] ;
// [timeLabel sizeToFit];
[footView addSubview:timeLabel];
上一篇:Codevs 3233 古道


下一篇:[学习笔记]设计模式之Composite