文檔學習 - UILabel - 屬性詳解

來源:互聯網
上載者:User

標籤:

#import "ViewController.h"

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // 1.

    UILabel *label = [[UILabel alloc] init];

    

    // 1.1 text

    label.text = @"//  ViewController.m01-UILabelCreated byjiaguanglei on 15/9/30Copyright (c) 2015年 roseonly. All rights reserved.";

    

    // 1.2 font

    /**

     const CGFloat UIFontWeightUltraLight;

     const CGFloat UIFontWeightThin;

     const CGFloat UIFontWeightLight;

     const CGFloat UIFontWeightRegular;

     const CGFloat UIFontWeightMedium;

     const CGFloat UIFontWeightSemibold;

     const CGFloat UIFontWeightBold;

     const CGFloat UIFontWeightHeavy;

     const CGFloat UIFontWeightBlack;

     

     + (UIFont *)systemFontOfSize:(CGFloat)fontSize;

     + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;   -- 粗體

     + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; -- 斜體

     + (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight NS_AVAILABLE_IOS(8_2);

     */

    label.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBlack];

    

    // 1.3 textColor

    label.textColor = [UIColor magentaColor];

    

    // 1.4 shadowColor

    label.shadowColor = [UIColor greenColor];

    

    // 1.5 shadowOffset

    label.shadowOffset = CGSizeMake(2, 2);

    

    // 1.6 textAlignment

    /**

     NSTextAlignmentLeft      = 0,    // Visually left aligned

     NSTextAlignmentCenter    = 1,    // Visually centered

     NSTextAlignmentRight     = 2,    // Visually right aligned

     NSTextAlignmentJustified = 3,   // Fully-justified. The last line in a paragraph is natural-aligned.

     NSTextAlignmentNatural   = 4,  // Indicates the default alignment for script

     */

    label.textAlignment = NSTextAlignmentLeft;

    

    // 1.7 lineBreakMode

    /**  --- 設定換行格式

     *  with long lines

     NSLineBreakByWordWrapping = 0, --- 以單詞為單位, 自動換行, 顯示不全, 沒有省略符號

     NSLineBreakByCharWrapping --- 以字元為單位自動換行, 沒有省略符號

     NSLineBreakByClipping     --- 直接切除, 可能顯示半個字元

     NSLineBreakByTruncatingHead --- 在行頭部, 顯示省略符號

     NSLineBreakByTruncatingTail --- 在行尾部, 顯示省略符號

     NSLineBreakByTruncatingMiddle --- 在行中間, 顯示省略符號

     */

    label.lineBreakMode = NSLineBreakByTruncatingTail;

 

    // 1.8 highlighted

    // 1.8.1 highlightedTextColor

    label.highlighted = NO;

    label.highlightedTextColor = [UIColor blackColor];

    

    // 1.9 enabled

    // 1.9.1 userInteractionEnabled

    label.enabled = YES;

    label.userInteractionEnabled = YES;

    

    // 1.10 numberOfLines

    label.numberOfLines = 0;

    

    // 1.11 adjustsFontSizeToFitWidth

    label.adjustsFontSizeToFitWidth = YES;

    // 1.11.1 adjustsLetterSpacingToFitWidth  --  已到期, 用NSKernAttributeName替換

    // 1.11.2 minimumFontSize  --- --  已到期, 用minimumScaleFactor替代

    label.minimumScaleFactor = .8;

    // 1.11.3 baselineAdjustment

    /**

     UIBaselineAdjustmentAlignBaselines = 0, // default.

     UIBaselineAdjustmentAlignCenters,

     UIBaselineAdjustmentNone,

     */

    label.baselineAdjustment = UIBaselineAdjustmentNone;

    

    // 1.12 -- 繪圖中可能會用到

    /**

     - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;

     - (void)drawTextInRect:(CGRect)rect;

     

     @property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);

     */

    

    // 1.13 attributedText

    NSDictionary *attrs = @{NSForegroundColorAttributeName : [UIColor redColor]};

    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:label.text attributes:attrs];

    

    label.attributedText = attrString;

    

    CGSize size = [UIScreen mainScreen].bounds.size;

    label.frame = CGRectMake(10, 100, size.width - 20, 50);

 

    label.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:label];

    

    

}

 

文檔學習 - UILabel - 屬性詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.