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

  • 相关阅读:
    Oracle存储过程基础
    LoadRunner常用知识点-----LoadRunner日志输出
    Action(8):Error-26608:HTTP Status-Code=504(Gateway Time-out)
    Action(8):Error -27728:Step download timeout(120 seconds)has expired when downloading
    windows7无声音,提示未插入扬声器或耳机的解决
    解决loadrunner 脚本和replaylog中的中文乱码问题
    LoadRunner11-遇到问题及解决办法(汇总)
    java内存溢出分析工具
    Loadrunner乱码问题
    LoadRunner常用函数
  • 原文地址:https://www.cnblogs.com/adampei-bobo/p/6116469.html
Copyright © 2011-2022 走看看