#import"LabelViewController.h"
@implementation LabelViewController
/*
Accessing the Text Attributes
text property
font property
textColor property
textAlignment property
lineBreakMode property
enabled property
Sizing the Label’s Text
adjustsFontSizeToFitWidth property
baselineAdjustment property
minimumFontSize property 无例
numberOfLines property
Managing Highlight Values
highlightedTextColor property
highlighted property
Drawing a Shadow
shadowColor property
shadowOffset property
Drawing and Positioning Overrides
– textRectForBounds:limitedToNumberOfLines: 无例
– drawTextInRect: 无例
Setting and Getting Attributes
userInteractionEnabled property
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(50.0,20.0,200.0,50.0)];
//label的文字
label.text=@"label";
//设置字体:粗体,正常的是SystemFontOfSize
label.font= [UIFont SystemFontOfSize:20];
//设置文字颜色
label.textColor= [UIColor orangeColor];
//设置文字位置
label.textAlignment=UITextAlignmentRight;
=UITextAlignmentCenter;
//设置字体大小适应label宽度
label.adjustsFontSizeToFitWidth=YES;
//设置label的行数
label.numberOfLines=2;
label.backgroudColor=[UIColor clearColor]; //可以去掉背景色
//设置高亮
label.highlighted=YES;
label.highlightedTextColor= [UIColor orangeColor];
//设置阴影
label.shadowColor= [UIColorredColor];
label.shadowOffset=CGSizeMake(1.0,1.0);
//设置是否能与用户进行交互
label.userInteractionEnabled=YES;
//设置label中的文字是否可变,默认值是YES
label.enabled=NO;
//设置文字过长时的显示格式
label3.lineBreakMode=UILineBreakModeMiddleTruncation;//截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label.baselineAdjustment=UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
[self.view addSubview:label];}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[superdidReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[superdealloc];
}
@end