• iOS04- UIButton的小常识


    有些时候我们想让UIButton的title居左对齐,我们设置

    btn.textLabel.textAlignment = UITextAlignmentLeft

    是没有作用的,我们需要设置

    btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;

    但是问题又出来,此时文字会紧贴到做边框,我们可以设置

    btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);

    使文字距离做边框保持10个像素的距离。

    =======================================================

    设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:

    [btn.titleLabel setTextColor:[UIColorblackColor]];

    btn.titleLabel.textColor=[UIColor redColor];

    而是用:

    [btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];

    • //设置字体大小  
    •     label1.font = [UIFont systemFontOfSize:20.0];  
    •     label2.font = [UIFont boldSystemFontOfSize:20.0];//粗体
    •    //linebreakmode 文字打断模式(过长) 默认位NSLineBreakByWordWrapping  
    •     label2.lineBreakMode = NSLineBreakByClipping;
    •   //Managing Highlight values  
    •     //设置高亮  
    •     label1.highlighted = YES;  
    •     label1.highlightedTextColor = [UIColor orangeColor]; 

         添加边框,圆角和弧度。

    avatarImage = [UIButtonbuttonWithType:UIButtonTypeCustom];

            //给按钮加一个白色的板框

            avatarImage.layer.borderColor = [[UIColorwhiteColorCGColor];

            avatarImage.layer.borderWidth =1.0f;

            //给按钮设置弧度,这里将按钮变成了圆形

            avatarImage.layer.cornerRadius =25.0f;

            avatarImage.backgroundColor = [UIColorredColor];

            avatarImage.layer.masksToBounds =YES;

      前者用来设置文字的大小,后者后来设置文字的粗细

        UIFont *font = [UIFont systemFontOfSize:17.0f weight:UIFontWeightUltraLight];  

        self.lable.font = font;  

    1. NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:14],  
    2.                                  NSForegroundColorAttributeName: [UIColor redColor],  
    3.                                  NSStrokeWidthAttributeName: @-10};  
    1. self.lable.attributedText = [[NSAttributedString alloc] initWithString:@"字符串" attributes:attributes];  

    通过将字典数据attributes将值赋给lable.attributeText,可以设置lable中text的字号大小,颜色,外边宽度,外边颜色,甚至是阴影等各种属性。
    1. NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] init];  
    2. [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];  
    3. self.lable.attributedText = attributeStr;  


    通过创建可变的NSMutableAttributeString,然后调用添加方法,不仅可以设置lable的各种属性,还可以设置每种属性的影响范围,更加灵活。

    最后再补上各种常用属性的功能:

    NSFontAttributeName 设置字号

    NSParagraphStyleAttributeName 设置段落样式

    NSForegroundColorAttributeName 设置文字颜色

    NSBackgroundColorAttributeName 设置背景颜色

    NSStrokeColorAttributeName 设置外边颜色

    NSStrokeWidthAttributeName 设置外边宽度

    NSUnderlineStyleAttributeName 设置下划线

    NSUnderlineColorAttributeName 设置划线颜色

    NSStrikethroughStyleAttributeName 设置划线

    NSShadowAttributeName 设置阴影

    NSVerticalGlyphFormAttributeName 设置文本布局为横(输入值0即可,iOS不支持竖排版)

    NSObliquenessAttributeName 设置字体倾斜

    NSExpansionAttributeName 设置文字扁平化

    PS1:外边宽度和外边颜色同事设置时,文字会变为空心属性。但是当外边宽度为负值时,不会空心。

    PS2:设置阴影单独不可用,要和NSVerticalGlyphFormAttributeName,NSObliquenessAttributeName,NSExpansionAttributeName一起使用才行。

    继续添加iOS支持的中文字体的模样

    Heiti SC

    STHeitiSC-Light

    STHeitiSC-Medium
    Heiti TC
    STHeitiTC-Light
    STHeitiTC-Medium
    Hiragino Kaku Gothic ProN
    HiraKakuProN-W3
    HiraKakuProN-W6
    Hiragino Mincho ProN
    HiraMinProN-W3
    HiraMinProN-W6

     

     

  • 相关阅读:
    UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
    UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
    容斥原理、鸽巢原理快速入门
    HDU.1847 Good Luck in CET-4 Everybody! ( 博弈论 SG分析)
    HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
    POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
    HDU.2516 取石子游戏 (博弈论 斐波那契博弈)
    HDU.2147 kiki's game (博弈论 PN分析)
    Front Page
    2018-2019 9th BSUIR Open Programming Championship. Semifinal
  • 原文地址:https://www.cnblogs.com/ytmaylover/p/5050202.html
Copyright © 2020-2023  润新知