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

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

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

    [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];

iOS UILable的一些用法的更多相关文章

  1. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  2. ios多线程-GCD基本用法

    ios中多线程有三种,NSTread, NSOperation,GCD 这篇就讲讲GCD的基本用法 平时比较多使用和看到的是: dispatch_async(dispatch_get_global_q ...

  3. iOS中block的用法 以及和函数用法的区别

    ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候  MyBlock(); 带参数的 ...

  4. iOS UIProgressView控件用法

    IOS中进度条控件的用法总结. 进度条控件是IOS开发中一个简单的系统控件,使用总结如下: 初始化一个进度条: - (instancetype)initWithProgressViewStyle:(U ...

  5. iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)

    1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...

  6. iOS block-base 动画简单用法+关键帧动画设置线性变化速度的问题

    本文转载至 http://www.tuicool.com/articles/aANBF3m 时间 2014-12-07 20:13:37  segmentfault-博客原文  http://segm ...

  7. iOS UILable和属性字符串的使用

    UILable的常用方法和属性 设置文字颜色(默认为黑色) @property(nonatomic,strong) UIColor     *textColor 设置显示文字 @property(no ...

  8. ios中图片拉伸用法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  9. iOS中的CocoaPods用法及常用命令

     CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...

随机推荐

  1. 利用UIImagePickerController或者利用UIKit的 UIGraphicsBeginImageContext保存图片

    转载自:http://my.oschina.net/hmj/blog/99970    应用中有时我们会有保存图片的需求,如利用UIImagePickerController用IOS设备内置的相机拍照 ...

  2. struts2 集成 easyui

    关键点: json数据格式 获取json数据 输出json 分页 #json数据格式# datagrid: {"total":1,"rows":[{" ...

  3. ASP.NET MVC- 解决HTML转码

    在MVC里从Controller发送一段带有HTML的文字到View视图时,MVC是会将这段代码进行转码的. 一.使用MvcHtmlString转HTML转码 如果想不让这段文字进行转码,以HTML的 ...

  4. Spring中使用Hibernate

    在context中定义DataSource,创建SessionFactoy,设置参数: DAO类继承HibernateDaoSupport,实现具体接口,从中获得HibernateTemplate进行 ...

  5. ASP.NET基础之HttpModule 、HttpContext、 HttpHandler

    http://www.cnblogs.com/wujy/p/3261141.html http://www.cnblogs.com/wujy/p/3264475.html http://www.cnb ...

  6. new 运算符

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/new

  7. 利用Retrofit, RxJava获取网络内容

    Retrofit & RxJava 关于如何使用Retrofit和RxJava请阅读参考中的两篇文章. Retrofit处理数据 Retrofit是在什么时候处理从网络中获取到的json数据的 ...

  8. 自行架设DNS的操作步骤及相关说明

    关于什么是DNS及相关的名词及说明,请看 http://www.wdlinux.cn/bbs/viewthread.php?tid=1081&highlight=dns这里,只是说明,在wdd ...

  9. 如何查询redhat的版本信息

    cat /etc/redhat-release lsb_release -a

  10. CSS Gradient文字效果

    你想创建的标题没有渲染和Photoshop每个标题吗?这里是一个简单的CSS技巧向您展示如何创建渐变文字效果,PNG图像(纯CSS,没有Javascript或Flash).你所需要的是一个空的< ...