IOS基礎-UILabel

來源:互聯網
上載者:User

IOS基礎-UILabel

最普通的文字標籤, 說白了就是一個字串的集合,來展示文本用的。

如下詳細說明了label的各種屬性

 

- (void)viewDidLoad{    [super viewDidLoad];        UILabel *label = [[UILabel alloc] init];        //設定顯示的文字    label.text = @"這是一個文本控制項";    //設定顯示的文字字型    label.font = [UIFont systemFontOfSize:18.0];    //設定文字顏色    label.textColor = [UIColor redColor];    //設定陰影顏色    label.shadowColor = [UIColor greenColor];    //設定陰影的大小    label.shadowOffset = CGSizeMake(1.0, 1.0);    /*     typedef NS_ENUM(NSInteger, NSTextAlignment)      {         NSTextAlignmentLeft      = 0,      // 靠左對齊         #if   iphone           NSTextAlignmentCenter    = 1,    // 置中           NSTextAlignmentRight     = 2,    // 靠右對齊         #else  ipad           NSTextAlignmentRight     = 1,    // Visually right aligned           NSTextAlignmentCenter    = 2,    // Visually centered         #endif  其他           NSTextAlignmentJustified = 3,    // 和段落對齊           NSTextAlignmentNatural   = 4,    // 預設狀態  正常情況下     } NS_ENUM_AVAILABLE_IOS(6_0);     */    //文字顯示模式    label.textAlignment = NSTextAlignmentCenter;    //設定自動換行  不過是在ios使用 現在已經到期    label.lineBreakMode = UILineBreakModeCharacterWrap;    //現在可以使用這個換行    label.numberOfLines = 0;    //設定高亮狀態下的文字顏色    label.highlightedTextColor = [UIColor greenColor];    //設定字型最小值  不過minimumFontSize已經到期     label.minimumFontSize = 18.0;    label.minimumScaleFactor = 18.0;    //設定控制項對象的大小是否隨標題內容的大小自動調整    [label setAutoresizesSubviews:true];    //設定使用者可不可以操作    label.userInteractionEnabled = NO;    //設定控制項的狀態 YES為可用    label.enabled = YES;    //指定了線寬度的最大值,以便計算固有內容大小    /*     UILabel和NSTextField對於多行文本的固有內容大小是模糊不清的。     文本的高度取決於線的寬度,這也是解決約束條件時需要弄清的問題。     為瞭解決這個問題,這兩個類都有一個叫做preferredMaxLayoutWidth的屬性,     這個屬性指定了線寬度的最大值,以便計算固有內容大小。     */    label.preferredMaxLayoutWidth = 19.0;        //設定文本字型是否要減小來適應label的地區    label.adjustsFontSizeToFitWidth = NO;        /*     typedef NS_ENUM(NSInteger, UIBaselineAdjustment) {     UIBaselineAdjustmentAlignBaselines = 0, // 預設 文本最上端於label中線對齊     UIBaselineAdjustmentAlignCenters,       // 文本中線於label中線對齊     UIBaselineAdjustmentNone,               // 文本最低端與label中線對齊     };     */    //這個值設定文本的基準位置    label.baselineAdjustment = UIBaselineAdjustmentAlignBaselines;        //把文本添加到控制器的視圖中    [self.view addSubview:label];    


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.