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];
随机推荐
- PLSQL数据库操作(excel)
一.plsql数据库操作: 删除数据前备份一张表: create table plat_counter_def_bf as select * from plat_monitor_counter_def ...
- Android 控件的显示隐藏上下左右移动动画
一.利用Android提供的左右移动工具类:AnimationUtils 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 LinearLayout ll_fi ...
- Node.js-安装配置【1】-在Windows XP系统配置环境变量
家里有台老古董台式机,安装的是Windows XP系统,摸索了一下,成功的在上面安装配置好了Node.js V4.4.7 一.安装Node.js(过程略) 二.npm配置全局和缓存路径(过程略) 三. ...
- C#中的Json的序列化和反序列化
Json是一种通用的数据格式,我们在数据交换的时候,经常会用到,下面介绍c#中的json序列化和反序列化,当然也可用在asp.net,silverlight,wpf中.我们在下面实例讲解如何进行Jso ...
- ASP.NET页面的字符编码设置
在用ASP.NET写网上支付的接口程序时,遇到一个奇怪问题,通过表单提交过去的中文全是乱码,英文正常.而用asp程序进行测试,可以正常提交中文,asp页面中有这样的HTML代码: <meta h ...
- python之 sqlalchemy
one To many #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @author: zengchunyun & ...
- springboot与shiro配置
详情参考: http://blog.csdn.net/catoop/article/details/50520958 http://blog.csdn.net/qiuqiupeng/article/ ...
- webdriverAPI-Java
1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide:http://seleniu ...
- JavaScript:数组大全
栈/队列 数组es3: pop删除最后一项(栈) shift删除第一项(队列) push增加到最后(栈) unshift增加到最前(队列) reverse翻转 join转字符串 slice截取(切片) ...
- kafka模块概述
简介 kafka主要用于实现低延迟的发送和收集大量的事件和日志数据--通常是活跃的数据(PV.访问记录等),数据以日志形式记录下来,然后由一个专门的系统来进行日志的收集与统计: 吞吐量极高的分布式消息 ...