UILabel的属性和用法

#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容