1 #import "LabelTestViewController.h" 2 @implementation LabelTestViewController 3 /* 4 Accessing the Text Attributes 5 text property 6 font property 7 textColor property 8 textAlignment property 9 lineBreakMode property 10 enabled property 11 Sizing the Label’s Text 12 adjustsFontSizeToFitWidth property 13 baselineAdjustment property 14 minimumFontSize property 無例 15 numberOfLines property 16 Managing Highlight Values 17 highlightedTextColor property 18 highlighted property 19 Drawing a Shadow 20 shadowColor property 21 shadowOffset property 22 Drawing and Positioning Overrides 23 – textRectForBounds:limitedToNumberOfLines: 無例 24 – drawTextInRect: 無例 25 Setting and Getting Attributes 26 userInteractionEnabled property 27 */ 28 29 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 30 - (void)viewDidLoad { 31 UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)]; 32 UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 80.0, 200.0, 50.0)]; 33 UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 140.0, 200.0, 50.0)]; 34 UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 200.0, 200.0, 50.0)]; 35 UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 260.0, 200.0, 50.0)]; 36 UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 320.0, 200.0, 50.0)]; 37 UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)]; 38 39 //設置顯示文字 40 label1.text = @"label1"; 41 label2.text = @"label2"; 42 label3.text = @"label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--"; 43 label4.text = @"label4--label4--label4--label4--"; 44 label5.text = @"label5--label5--label5--label5--label5--label5--"; 45 label6.text = @"label6"; 46 label7.text = @"label7"; 47 48 //設置字體 49 label1.font = [UIFont boldSystemFontOfSize:20]; 50 51 //設置文字顏色 52 label1.textColor = [UIColor orangeColor]; 53 label2.textColor = [UIColor purpleColor]; 54 55 //設置文字位置 56 label1.textAlignment = UITextAlignmentRight; 57 label2.textAlignment = UITextAlignmentCenter; 58 //設置字體大小適應label寬度 59 label4.adjustsFontSizeToFitWidth = YES; 60 61 //設置label的行數 62 label5.numberOfLines = 2; 63 64 //設置高亮 65 label6.highlighted = YES; 66 label6.highlightedTextColor = [UIColor orangeColor]; 67 68 //設置陰影 69 label7.shadowColor = [UIColor redColor]; 70 label7.shadowOffset = CGSizeMake(1.0,1.0); 71 72 //設置是否能與用戶進行交互 73 label7.userInteractionEnabled = YES; 74 75 //設置label中的文字是否可變,默認值是YES 76 label3.enabled = NO; 77 78 //設置文字過長時的顯示格式 79 label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中間 80 // typedef enum { 81 // UILineBreakModeWordWrap = 0, 82 // UILineBreakModeCharacterWrap, 83 // UILineBreakModeClip,//截去多餘部分 84 // UILineBreakModeHeadTruncation,//截去頭部 85 // UILineBreakModeTailTruncation,//截去尾部 86 // UILineBreakModeMiddleTruncation,//截去中間 87 // } UILineBreakMode; 88 89 //若是adjustsFontSizeToFitWidth屬性設置爲YES,這個屬性就來控制文本基線的行爲 90 label4.baselineAdjustment = UIBaselineAdjustmentNone; 91 // typedef enum { 92 // UIBaselineAdjustmentAlignBaselines, 93 // UIBaselineAdjustmentAlignCenters, 94 // UIBaselineAdjustmentNone, 95 // } UIBaselineAdjustment; 96 97 98 [self.view addSubview:label1]; 99 [self.view addSubview:label2]; 100 [self.view addSubview:label3]; 101 [self.view addSubview:label4]; 102 [self.view addSubview:label5]; 103 [self.view addSubview:label6]; 104 [self.view addSubview:label7]; 105 106 [label1 release]; 107 [label2 release]; 108 [label3 release]; 109 [label4 release]; 110 [label5 release]; 111 [label6 release]; 112 [label7 release]; 113 114 [super viewDidLoad]; 115 } 116 117 /* 118 // Override to allow orientations other than the default portrait orientation. 119 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 120 // Return YES for supported orientations 121 return (interfaceOrientation == UIInterfaceOrientationPortrait); 122 } 123 */ 124 - (void)didReceiveMemoryWarning { 125 // Releases the view if it doesn't have a superview. 126 [super didReceiveMemoryWarning]; 127 128 // Release any cached data, images, etc that aren't in use. 129 } 130 - (void)viewDidUnload { 131 // Release any retained subviews of the main view. 132 // e.g. self.myOutlet = nil; 133 } 134 135 - (void)dealloc { 136 [super dealloc]; 137 } 138 @end
轉帖來源於此:http://wiki.eoe.cn/page/iOS_blog_page_91033.htmlhtml
如:調用電話功能、調用safar打開網頁等ide
http://blog.163.com/cz_jdton/blog/static/92732504201292310161928/字體