UIButton的titleLabe setAttributeSting 首次不起作用
环境xcode7.3 ios9.3 真机模拟器均出现 UIButton的titleLabe setAttributeSting 首次不起作用,之后每一次 都正常,百思不得解,无奈之下改变策略,讲button title设置空,就是不设置title,另外加一个Label 把要设置 attributeString 设置在单独label 上,再加Btn aad 在label上,Button 与 Label 大小相等。完美解决button titleLabel setAttributeSting首次不起作用的问题.
code 如下:
#pragma mark 显示最近地铁站路线
- (void)showWayToStationWithStation:(SubwayStationModel *)station from:(CLLocationCoordinate2D) coordinate distance:(double)distance{
_wayLabel.frame = CGRectMake(, SCREEN_HEIGHT--, SCREEN_WIDTH, );
NSString *title = [NSString stringWithFormat:@"距离最近的地铁站\n%@ %ld米\n查看步行线路",station.stationName,(long)distance]; [_wayLabel setText:title]; NSString *string = title;
NSRange rangeLeft = [title rangeOfString:@"距离最近的地铁站"];
NSRange rangeRight = [title rangeOfString:@"查看步行线路"];
NSRange rangeCenter = NSMakeRange(rangeLeft.length, rangeRight.location - rangeLeft.length);
NSRange rangeAll = NSMakeRange(, title.length); NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:string]; [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.087 green:0.024 blue:0.023 alpha:1.000] range:rangeLeft];
[attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:1.000 green:0.288 blue:0.268 alpha:1.000] range:rangeCenter];
[attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.043 green:0.431 blue:0.046 alpha:1.000] range:rangeRight];
[attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:] range:rangeCenter];
[attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:] range:rangeRight]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineSpacing = 2.5;
style.alignment = NSTextAlignmentCenter;
[attributeStr addAttribute:NSParagraphStyleAttributeName value:style range:rangeAll];
[_wayLabel setAttributedText:attributeStr]; [UIView animateWithDuration:0.35 animations:^{
_wayLabel.mkY -= ;
} completion:^(BOOL finished) {
[self performSelector:@selector(hiddenShowWayView) withObject:nil afterDelay:];
}]; } - (void)hiddenShowWayView{
[UIView animateWithDuration:0.35 animations:^{
_wayLabel.mkY += ;
} completion:^(BOOL finished) { }];
}
UIButton的titleLabe setAttributeSting 首次不起作用的更多相关文章
- 005.操作系统及Linux系统,虚拟机的作用和发展历史
操作系统及其作用 操作系统发展史 Linux系统 虚拟机 操作系统 操作系统 操作系统的作用 不同领域的主流操作系统 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有 ...
- Lotus开发性能优化
之前也总结过一篇关于性能的文章,地址在http://www.cnblogs.com/carysun/archive/2008/08/09/BasicPerformance.html,今天又看到DW上又 ...
- linux介绍、命令(基本命令、常用命令、使用方法、基本格式)
操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 一个例子说明操作系统 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如 ...
- Linux - 操作系统
操作系统(科普章节) 目标 了解操作系统及作用 1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自 ...
- Iphone开发基本UI组件
在IOS中的基础UI组件,IPHONE的组件大多以UI开头,这种独树一帜的命名方法极有可能是为了与其他系统的组件进行区分,避免混淆引起冲突: 下面描述一下IOS的基础UI控件以及和Android中的 ...
- 5、Linux操作系统介绍
1操作系统的作用·是现代计算机系统中最基本和最重要的系统软件·是配置在计算机硬件上的第一层软件,是对硬件系统的首次扩展·主要作用是管理好硬件设备,并为用户和应用程序提供一个简单的接口,以便于使用·而其 ...
- 操作系统 (OS)
1. 操作系统(Operation System,OS) 操作系统作为接口的示意图 没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计 ...
- Linux 操作系统介绍
应用软件——操作系统——硬件 操作系统的作用 是现代计算机系统中最基本和最重要的系统软件 是配置在计算机硬件上的第一层软件,是对硬件系统的首次扩展 主要作用是管理好硬件设备,并为用户和应用程序提供一个 ...
- Linux系统基础认知
什么是操作系统? 操作系统作为接口的示意图: 没有安装操作系统的计算机,通常被称为裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计算机上安装了操作系统,就可以在操作系统上 ...
随机推荐
- Javascript 事件对象(六)事件默认行为
事件默认行为: 阻止默认事件普通写法:return false;屏蔽右键菜单 : oncontextmenu <!DOCTYPE HTML> <html> <head& ...
- XenServer安全重启xapi的方法
XenServer安全重启xapi的方法 2012-11-29 12:58:07| 分类: 虚拟化-XenServer|字号 订阅 平常我们很常用到重启xapi命令,在这介绍下xapi: XAPI( ...
- 【转】Qt下使用glut库
ps:这个说的很明白,尤其是win10环境下用mingw环境时编程时碰到的问题, 1.加 windows.h 2.在.pro 添加libs 博文地址:Qt下使用glut库 本人使用的环境 ...
- pylab,matplotlib Invalid DISPLAY variable
在cetos 服务器使用源码包,安装matplotlib, 安装成功后, import pylab as pl pl.figure(figsize=(16,8)) python 解析器报错,Inval ...
- 使用VC6开发opengl配置
2015-11-09 22:25 VC6中工程创建: (1)创建一个Win32 Console Application.(以我创建的为例,工程名为simpleGL) (2)链接OpenGL li ...
- Android常用库
原文链接:http://www.jianshu.com/p/19368c2cdcaf 系统框架 1. 网络请求 Android Async HTTP Android异步HTTP库 AndroidAsy ...
- MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解决办法和原因
这两天下载了MySQL5.7.11进行安装,发现到了初次使用输入密码的时候,不管怎样都进不去,即使按照网上说的在mysqld 下面添加skip-grant-tables也是不行,后来研究了两天,终于找 ...
- Scrolliview
package com.example.scrollview; import android.os.Bundle;import android.app.Activity;import android. ...
- System.Linq.Enumerable 中的方法 Aggregate 函数
语法: public static TSource Aggregate<TSource>( this IEnumerable<TSource> source, Func&l ...
- Kali Linux additional tools setup
The steps are pretty straight forward. The only tool that might cause some confusion is SMBexec. Thi ...