iOS - UIButton设置文字标题下划线以及下划线颜色
创建button设置可以折行显示
- (void)viewDidLoad {
[super viewDidLoad];
UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(20, 30, 150, 70)];
[self.view addSubview:button];
[button setTitle:@"button" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//button 折行显示设置
/*
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
NSLineBreakByCharWrapping, // Wrap at character boundaries
NSLineBreakByClipping, // Simply clip 裁剪从前面到后面显示多余的直接裁剪掉
文字过长 button宽度不够时: 省略号显示位置...
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz" 前面显示
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..." 后面显示
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz" 中间显示省略号
*/
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// you probably want to center it
button.titleLabel.textAlignment = NSTextAlignmentCenter; // if you want to
button.layer.borderColor = [UIColor blackColor].CGColor;
button.layer.borderWidth = 1.0;
// underline Terms and condidtions
NSMutableAttributedString* tncString = [[NSMutableAttributedString alloc] initWithString:@"View Terms and Conditions"];
//设置下划线...
/*
NSUnderlineStyleNone = 0x00, 无下划线
NSUnderlineStyleSingle = 0x01, 单行下划线
NSUnderlineStyleThick NS_ENUM_AVAILABLE(10_0, 7_0) = 0x02, 粗的下划线
NSUnderlineStyleDouble NS_ENUM_AVAILABLE(10_0, 7_0) = 0x09, 双下划线
*/
[tncString addAttribute:NSUnderlineStyleAttributeName
value:@(NSUnderlineStyleSingle)
range:(NSRange){0,[tncString length]}];
//此时如果设置字体颜色要这样
[tncString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,[tncString length])];
//设置下划线颜色...
[tncString addAttribute:NSUnderlineColorAttributeName value:[UIColor redColor] range:(NSRange){0,[tncString length]}];
[button setAttributedTitle:tncString forState:UIControlStateNormal];
}
- 设置button的下划线直接设置文字的属性
NSMutableAttributedString
的tncString
添加文字属性NSUnderlineStyleAttributeName
并设置下划线样式,NSUnderlineStyleNone
-- 无下划线,NSUnderlineStyleSingle
-- 单行下划线,NSUnderlineStyleThick
-- 单行加粗下划线,NSUnderlineStyleDouble
-- 双下划线. - 设置下划线颜色属性
NSUnderlineColorAttributeName
- 最主要的是设置button的标题为
NSMutableAttributedString
包含多种属性的字符串string.
UILabel下划线设置: http://www.cnblogs.com/adampei-bobo/p/6500782.html
iOS - UIButton设置文字标题下划线以及下划线颜色的更多相关文章
- iOS UIButton 图片文字上下垂直布局 解决方案
实现如图所示效果: 这是一个UIButton,需要改变image和title相对位置. 解决如下: //设置文字偏移:向下偏移图片高度+向左偏移图片宽度 (偏移量是根据[图片]大小来的,这点是关键)b ...
- iOS - UIButton设置图片文字上图下文排列
经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButton ...
- ios UIButton设置高亮状态下的背景色
一,通过按钮的事件来设置背景色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - (void)viewDidLoad { [ ...
- ios UIButton设置单选效果,以及同时设置图片和标题
一,设置单选效果 - (void)selectedBtnPress:(UIButton*)sender { //首先把原来按钮的选中效果消除 for (int i=0;i<num;i++) {/ ...
- iOS UIButton 设置图片文字垂直排列
后面经过测试,如果button的文字长度变更,会导致图片位置变化,经过多次修改UIEdgeInsets的值也没有达到期望效果,最终采用集成UIButton类,重写layoutSubviews函数实现, ...
- iOS·UIButton如何文字在下图片在上
创建子类继承自UIButton,在layoutSubviews方法中改变文字和图片的位置就可以了,同理,稍作改变,可以写出文字在上图片在下.本文只给出文字在下图片在上的代码 -(void)layout ...
- iOS UIButton 图片文字左右互移 位置对调 解决方案
实现类似效果: 代码实现: btnGrade.titleEdgeInsets = UIEdgeInsetsMake(, -(btnGrade.imageView?.bounds.width)!, , ...
- iOS UIButton 设置图片平铺
UIImage *image2 = [UIImage imageNamed:imgName]; CGFloat top = ; // 顶端盖高度 CGFloat bottom = ; // 底端盖高度 ...
- iOS UIButton 设置图片不变型setImage
[btn.imageView setContentMode:UIViewContentModeScaleAspectFill];
随机推荐
- UWP 设备分辨率
之前看了下网上,分辨率都是用webview js拿或者全屏拿宽高,很有局限性. 研究一下.找到个完美的方法: public Size GetDeviceResolution() { Size reso ...
- git学习(一):建立本地仓库和基本命令
前沿 最近一直在做目标跟踪,开始一直是通过文件按日期命名的方式来区分版本的,实在是太麻烦了,现在下定决心学习一下git命令 基本概念 集中式:有一台中央服务器,每个人把需要改的部分拿回去改完再送回来 ...
- suse最小化安装
Open suse 图形安装 用虚拟机vmware70 或者是Oracle VM VirtualBox安装 .镜像文件就是SLED-10-x86_64-DVD1 根据虚拟机设置吧镜像文件装入虚拟机中 ...
- TextView链接点击和长按冲突
1.重写 import android.text.Layout; import android.text.Selection; import android.text.Spannable; impor ...
- 本机tomcat的server.xml被还原的问题及解决办法
将tomcat的server.xml进行修改,但当eclipse发布站点后,发布tomcat中的server.xml会被还原. 原因是eclipse会将自己的tomcat配置文件对tomcat覆盖,解 ...
- 开机自动启动Tomcat
一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2.安装Tomc ...
- WebCrawler
WebCrawler WebCrawler is a metasearch engine that blends the top search results from Google Search a ...
- js的三种继承方式及其优缺点
[转] 第一种,prototype的方式: //父类 function person(){ this.hair = 'black'; this.eye = 'black'; this.skin = ' ...
- ubuntu14.04下安装ngnix,mediawiki,nodebb,everything,gitlab
本周折腾了以下几个东西,mediawiki(维基),nodebb(论坛),gitlab(私有git服务器). 本来的目的是搭建一个wiki,选用了mediawiki后,使用apache搭建好了. 搭论 ...
- AD Local Domain groups, Global groups and Universal groups
http://ss64.com/nt/syntax-groups.html Rules that govern when a group can be added to another group ( ...