#import "ViewController.h"app
@implementation ViewControlleratom
- (void)viewDidLoad {seo
[super viewDidLoad];ip
// 1.ci
UILabel *label = [[UILabel alloc] init];it
// 1.1 textio
label.text = @"// ViewController.m01-UILabelCreated byjiaguanglei on 15/9/30Copyright (c) 2015年 roseonly. All rights reserved.";ast
// 1.2 fontimport
/**im
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];
}