UILabel屬性及應用
UILabel *label1 =[ [UILabel alloc] initWithFrame:CGRectMake(20,40,280,80)]; //創建label
label1.backgroundColor = [ UIColor grayColor];
label1.tag = 91; //設置tag
label1.text = @"helloworld"; //設置標籤文本
label1.font = [ UIFont fontWithName:@"Arial" size:30]; //文本字體和文本大小
label1.textAlignment = UITextAlignmentCenter; //對齊方式
typedef enum{
UITextAlignmentLeft = 0, //左對齊
UITextAlignmentCenter, //居中對齊
UITextAlignmentRight, //右對齊
}UITextAlignment;
label1.textColor = [ UIColor blueColor]; //設置文本顏色
label1.lineBreakMode = UILineBreakModeTailFruncation; //超出label1邊界文字的截取方式
typedef enum{
UILineBreakModeWordWrap = 0, //以空格爲邊界,保留整個單詞
UILineBreakModeCharacterWrap, //保留整個字符
UILineBreakModeClip, //到邊界爲止
UILineBreakModeHeadTruncation, //省略開始,以... ... 代替
UILineBreakModeTailTruncation, //省略結尾,以... ...代替
UILineBreakModeMiddleTruncation,//省略中間,以... ...代替,多行時作用於最後一行
}
label1.adjustsFontSizeToFitWidth = YES; //文本文字自適應大小(如果文本font要偏小時)
label1.baselineAdjustment = UIBaselineAdjustmentAlignCenters; //控制文本基線位置,一行文本有效
typedef enum{
UIBaselineAdjustmentAlignBaselines = 0, //默認值文本上端位於label1中線對齊
UIBaselineAdjustmentAligncenters, //文本中線位於label1中線對齊
UIBaselineAdjustmentNone, //文本最低端與label1中線對齊
}UIBaselineAdjustment;
label1.numberOfLine = 2; //文本最多行數,爲0時沒有最大行數限制
label1.minimumFontSize = 10.0; //最小字體行數爲1時有效 默認0.0
label1.highlighted = YES; //設置文本高亮
label1.enabled = YES; //文本是否可變
label1.backgroundColor = [ UIColor clearColor]; //去掉背景色
label1.shadowColor = [ UIColor grayColor]; //文本陰影顏色
label1.shadowOffset = CGRectMake(1.0,1.0); //陰影大小
label1.userInteractionEnabled = YES; //能否與用戶交互
[self.view addSubView:label1];
[label1 release];