创建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的下划线直接设置文字的属性NSMutableAttributedStringtncString添加文字属性NSUnderlineStyleAttributeName并设置下划线样式,NSUnderlineStyleNone -- 无下划线,NSUnderlineStyleSingle -- 单行下划线,NSUnderlineStyleThick -- 单行加粗下划线,NSUnderlineStyleDouble -- 双下划线.
  • 设置下划线颜色属性NSUnderlineColorAttributeName
  • 最主要的是设置button的标题为NSMutableAttributedString包含多种属性的字符串string.

UILabel下划线设置: http://www.cnblogs.com/adampei-bobo/p/6500782.html

iOS - UIButton设置文字标题下划线以及下划线颜色的更多相关文章

  1. iOS UIButton 图片文字上下垂直布局 解决方案

    实现如图所示效果: 这是一个UIButton,需要改变image和title相对位置. 解决如下: //设置文字偏移:向下偏移图片高度+向左偏移图片宽度 (偏移量是根据[图片]大小来的,这点是关键)b ...

  2. iOS - UIButton设置图片文字上图下文排列

    经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButton ...

  3. 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 {     [ ...

  4. ios UIButton设置单选效果,以及同时设置图片和标题

    一,设置单选效果 - (void)selectedBtnPress:(UIButton*)sender { //首先把原来按钮的选中效果消除 for (int i=0;i<num;i++) {/ ...

  5. iOS UIButton 设置图片文字垂直排列

    后面经过测试,如果button的文字长度变更,会导致图片位置变化,经过多次修改UIEdgeInsets的值也没有达到期望效果,最终采用集成UIButton类,重写layoutSubviews函数实现, ...

  6. iOS·UIButton如何文字在下图片在上

    创建子类继承自UIButton,在layoutSubviews方法中改变文字和图片的位置就可以了,同理,稍作改变,可以写出文字在上图片在下.本文只给出文字在下图片在上的代码 -(void)layout ...

  7. iOS UIButton 图片文字左右互移 位置对调 解决方案

    实现类似效果: 代码实现: btnGrade.titleEdgeInsets = UIEdgeInsetsMake(, -(btnGrade.imageView?.bounds.width)!, , ...

  8. iOS UIButton 设置图片平铺

    UIImage *image2 = [UIImage imageNamed:imgName]; CGFloat top = ; // 顶端盖高度 CGFloat bottom = ; // 底端盖高度 ...

  9. iOS UIButton 设置图片不变型setImage

    [btn.imageView setContentMode:UIViewContentModeScaleAspectFill];

随机推荐

  1. Delphi 各版本新特性功能网址收集

    Delphi XE2 三个新功能介绍举例_西西软件资讯  http://www.cr173.com/html/13179_1.html delphi 2007新功能简介-davidxueer-Chin ...

  2. [软件推荐]VMware Workstation 12.1.1多国语言(含简体中文)+激活方法

    虚拟机VMware功能强大,使用方便,可以在同一台电脑上安装多个系统(Windows.Linux.OS).虚拟机上的所有操作都不会影响到“实体机”,因此在虚拟机中可以进行很多测试操作,如果某些软件使用 ...

  3. CodeForces 544A

    You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...

  4. [转]Nodejs基础中间件Connect

    Nodejs基础中间件Connect 从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的J ...

  5. Leetcode Word Ladder

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  6. [Java] 位运算

    https://ckjoker.github.io/2015/03/01/Java-bit-primary/

  7. [我的试题]Test of String

    1.前言 这是我出的第一套题目,话说感觉有点晚了,还是在向总安排下出的.我被安排的是字符串方面的内容,这应该相对而言是比较小众的知识点吧,但是一样的有作用的,也有很神的题目.所谓是NOIP模拟题,其实 ...

  8. mysql分区操作

    分区表使用myisam引擎. 分区规则: Range(范围)–这种模式允许将数据划分不同范围.例如可以将一个表通过年份划分成若干个分区. Hash(哈希)–这中模式允许通过对表的一个或多个列的Hash ...

  9. *HDU 1068 二分图

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. centos关闭防火墙

    Centos7 关闭防火墙 CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 1.直接关闭防火墙 systemctl stop firewalld.se ...