您的位置:首页 > 产品设计 > UI/UE

UILabel UI中添加文字框

2015-07-30 09:37 411 查看

1.UILabel的创建(initWithFrame)

例子:

UILabel *label1 =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 150,150)];


2.设置背景颜色(backgroundColor)

例子:

label1.backgroundColor =[UIColor cyanColor];


3.添加到window窗口中

例子:

[self.window addSubview:label1];


4.如果是手动清除内存就要加上这一步

(自动清除内存不需要这步)

例子:

[label1 release];


5.设置文本内容(text)

例子:

label.text =@" 你好,我是一二三";


6.文本内容的颜色(textColor)

例子:

label1.textColor =[UIColor redColor];


7.文本的对齐方式(默认是居左)

(textAlignment 是一个枚举类型)

例子:

label1.textAlignment =NSTextAlignmentCenter;


8.字体大小

例子:

label1.font =[UIFont systemFontOfSize:20];


9.设置行数,默认是一行,设置成0是行数的最大值

例子:

label1.numberOfLines =3;


10.让文本自己去适应label的尺寸,显示全部内容

例子:

[label1 sizeToFit];


11.设置边框

例子:

label1.layer.borderWidth =5;


12:圆角

例子:

label1.layer.cornerRadius =75;


13.阴影大小

label1.shadowOffset =CGSizeMake(2,1);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息