字体名字网址:http://blog.sina.com.cn/s/blog_6c9d5da50101fujl.html
加粗
加粗;
[UILabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
加粗并且倾斜
[UILabel setFont:[UIFont fontWithName:@"Helvetica-BoldOblique" size:20]];
设置文本是否高亮和高亮时的颜色
scoreLabel.highlighted = YES;
scoreLabel.highlightedTextColor = [UIColor orangeColor];
设置字体大小是否适应label宽度
label.adjustsFontSizeToFitWidth = YES;
如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
coreLabel.baselineAdjustment = UIBaselineAdjustmentNone
设置阴影的颜色和阴影的偏移位置
scoreLabel.shadowColor = [UIColor redColor];
scoreLabel.shadowOffset = CGSizeMake(1.0,1.0);
设置是否能与用户进行交互
scoreLabel.userInteractionEnabled = YES;
设置label中的文字是否可变,默认值是YES
scoreLabel.enabled = NO;
设置文字过长时的显示格式
label.lineBreakMode = UILineBreakModeWordWrap;
typedefenum {
UILineBreakModeWordWrap =0, // Wrap at word boundaries
UILineBreakModeCharacterWrap, // Wrap at character boundaries
UILineBreakModeClip, //截去多余部分 Simply clip when it hits the end of the rect截去多余部分
UILineBreakModeHeadTruncation, //截去头部Truncate at head of line: "...wxyz". Will truncate multiline text on first line
UILineBreakModeTailTruncation,//截去尾部 Truncate at tail of line: "abcd...". Will truncate multiline text on last line
UILineBreakModeMiddleTruncation,//截去中间 Truncate middle of line: "ab...yz". Will truncate multiline text in the middle
} UILineBreakMode;
创建UILabel的前期准备工作
1.我们之前选择手动管理内存所以要在@implementation AppDelegate对创建的方法进行释放
-(void)dealloc{
[_window release];
[super dealloc];
}
如果在扩展里设置了属性也要在上面的方法中进行释放
2.在- (BOOL)application:对window进行创建了所以也要进行释放
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];//release->alloc此地方如果选择自动管理内存的话是没有的 手动的时候我们要自己加上
UILabel总结—继承UIView
—特有显示文字功能
1.创建UILabel
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100,100,200,300)];
label.backgroundColor=[UIColor yellowColor];
[self.window addSubview:label];
[label release];
2.设置文本内容
label.text=@"建立和谐社会,做文明公民";
3.文本的对其方式(默认居中 center居中left左)
label.textAlignment=NSTextAlignmentCenter;
4.字体大小
(1)调用的方法是加号方法,可直接用类调用方法
(2)用类调用加号方法用对象调用减号方法
(3)这些加号方法没有内存管理所以就是便利构造器,直接调用
(4)label.font=[UIFont systemFontOfSize:28];
5.设置行数
默认是一行;设置成0行是行数的最大值
label.numberOfLines=0;
6.显示全部内容:
sizeToFit是让自己去适应label的尺寸
[label sizeToFit];
7.断行模式:
lineBreakMode是枚举类型,结果就是省略中间文字
label.lineBreakMode=NSLinebreakByTruncatingMiddle;
8.阴影大小
label.shadowOffset=CGSizeMake(2,1);
9.阴影颜色
label.shadowColor=[UIColor redColor];
10.设置边框
label.layer.borderWidth=1;
11.设置圆角
label.layer.cornerRadius=10;
12.抹掉多出来的部分
去掉多出来的颜色 抹掉的只是视觉上抹掉了
label.layer.masksToBounds=YES;
13.对label的frame设置
label.frame=CGRectMake(100,100,200,299);
14.修改视图位置:center
label.center=CGPointMake(200,100+75);
与frame相对应一下 CGPointmake是个结构体
15.视图保持的一个原则就是一个矩形区域