zoukankan      html  css  js  c++  java
  • iOS

    创建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

  • 相关阅读:
    Pure-ftpd无法连接到服务器 425错误
    jQuery 取选中的radio的值方法
    Linux中RM快速删除大量文件/文件夹方法
    CSS(七):浮动
    CSS(六):盒子模型
    CSS(五):背景、列表、超链接伪类、鼠标形状控制属性
    CSS(四):字体和文本属性
    CSS三:CSS的三种引入方式
    CSS(二):选择器
    CSS(一):CSS简介和基本语法
  • 原文地址:https://www.cnblogs.com/adampei-bobo/p/6116469.html
Copyright © 2011-2022 走看看