设为首页 加入收藏

TOP

iOS UILable的一些用法
2017-10-13 10:29:10 】 浏览:8912
Tags:iOS UILable 一些 用法

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

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

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

    [MyTools createMyImageview:topEditView frame:CGRectMake(widthAll-90, 12, 17, 16) imageName:@"离线课程_下载更多.png"];
    UIButton *downMoreButton = [MyTools createMyBtn:@"下载更多" frame:CGRectMake(widthAll-70, 10, 60, 20) uiview:topEditView uifont:14 color:[UIColor colorWithRed:92/255.0 green:218/255.0 blue:231/255.0 alpha:1]];
    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(0, 10, 100, 20)];
timeLabel.font = [UIFont systemFontOfSize:10];
timeLabel.textColor = [UIColor blackColor];
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"100:00/100:00"];
NSRange redRange
= NSMakeRange(0, [[noteStr string] rangeOfString:@"/"].location); [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange]; [timeLabel setAttributedText:noteStr] ; // [timeLabel sizeToFit]; [footView addSubview:timeLabel];

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS 杂笔-20(UIView和CALayer的.. 下一篇多层导航栏下的登陆注销架构

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目