
UILable是iPhone界面最基本的控件,主要用来显示文本信息。
常用属性和方法有:
1、创建
CGRect rect = CGRectMake(100, 200, 50, 50);
UILabel label = [[UILabel alloc] initWithFrame:rect];
2、text //设置和读取文本内容,默认为nil
labeltext = @”文本信息”; //设置内容
NSLog(@”%@”, labeltext); //读取内容
3、textColor //设置文字颜色,默认为黑色
labletextColor = [UIColor redColor];
4、font //设置字体大小,默认17
labelfont = [UIFont systemFontOfSize:20]; //⼀一般方法
labelfont = [UIFont boldSystemFontOfSize:20]; //加粗方法
labelfont = [UIFont fontWithName:@"Arial" size:16]; //指定
字体的方法
//还有⼀一种从外部导入字体的方法。
5、textAlignment //设置标签文本对齐方式。
labeltextAlignment = NSTextAlignmentCenter; //还有
NSTextAlignmentLeft、 NSTextAlignmentRight
6、numberOfLines //标签最多显示行数,如果为0则表示多行。
labelnumberOfLines = 2;
7、enabled //只是决定了Label的绘制方式,将它设置
为NO将会使文本变暗,表示它没有激活,这时向它设置颜色值是无效的。
labelenable = NO;
8、highlighted //是否高亮显示
labelhighlighted = YES;
labelhighlightedTextColor = [UIColor orangeColor]; //高亮
显示时的文本颜色
9、ShadowColor //设置阴影颜色
[label setShadowColor:[UIColor blackColor]];
10、ShadowOffset //设置阴影偏移量
[label setShadowOffset:CGSizeMake(-1, -1)];
11、baselineAdjustment //如果adjustsFontSizeToFitWidth属性设
置为YES,这个属性就来控制文本基线的行为。
labelbaselineAdjustment = UIBaselineAdjustmentNone;
UIBaselineAdjustmentAlignBaselines = 0,默认,文本最上端与中线对齐。
UIBaselineAdjustmentAlignCenters, 文本中线与label中线对齐。
UIBaselineAdjustmentNone, 文本最低端与label中线对齐。
12、Autoshrink //是否自动收缩
Fixed Font Size 默认,如果Label宽度小于文字长度时时,文字大小不自动缩放
minimumScaleFactor 设置最小收缩比例,如果Label宽度小于文字长度时,文字
进行收缩,收缩超过比例后,停止收缩。
minimumFontSize 设置最小收缩字号,如果Label宽度小于文字长度时,文字字号
减小,低于设定字号后,不再减小。//60以后不再使用了。
labelminimumScaleFactor = 05;
13、adjustsLetterSpacingToFitWidth //改变字母之间的间距来适应Label大小
myLabeladjustsLetterSpacingToFitWidth = NO;
14、 lineBreakMode //设置文字过长时的显示格式
labellineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显
示,后面部分省略不显示。
labellineBreakMode = NSLineBreakByClipping;剪切与文本宽度相同的内
容长度,后半部分被删除。
labellineBreakMode = NSLineBreakByTruncatingHead;前面部分文字
以……方式省略,显示尾部文字内容。
labellineBreakMode = NSLineBreakByTruncatingMiddle;中间的内容
以……方式省略,显示头尾的文字内容。
labellineBreakMode = NSLineBreakByTruncatingTail;结尾部分的内容
以……方式省略,显示头的文字内容。
labellineBreakMode = NSLineBreakByWordWrapping;以单词为显示单位显
示,后面部分省略不显示。
15、 adjustsFontSizeToFitWidth //设置字体大小适应label宽度
labeladjustsFontSizeToFitWidth = YES;
16、attributedText:设置标签属性文本。
NSString text = @"first";
NSMutableAttributedString textLabelStr =
[[NSMutableAttributedString alloc]
initWithString:text];
[textLabelStr
setAttributes:@{NSForegroundColorAttributeName :
[UIColor lightGrayColor], NSFontAttributeName :
[UIFont systemFontOfSize:17]} range:NSMakeRange(11,
10)];
labelattributedText = textLabelStr;
17、竖排文字显示每个文字加一个换行符,这是最方便和简单的实现方式。
labeltext = @"请\n竖\n直\n方\n向\n排\n列";
labelnumberOfLines = [labeltext length];
18、计算UIlabel 随字体多行后的高度
CGRect bounds = CGRectMake(0, 0, 200, 300);
heightLabel = [myLabel textRectForBounds:bounds
limitedToNumberOfLines:20]; //计算20行后的Label的Frame
NSLog(@"%f",heightLabelsizeheight);
19、UILabel根据字数多少自动实现适应高度
UILabel msgLabel = [[UILabel alloc]
initWithFrame:CGRectMake(15, 45, 0, 0)];
msgLabelbackgroundColor = [UIColor lightTextColor];
[msgLabel setNumberOfLines:0];
msgLabellineBreakMode = UILineBreakModeWordWrap;
msgLabelfont = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(290, 1000);
msgLabeltext = @"获取到的deviceToken,我们可以通过webservice服务提
交给net应用程序,这里我简单处理,直接打印出来,拷贝到net应用环境中使
用。";
CGSize msgSie = [msgLabeltext sizeWithFont:fonts
constrainedToSize:size];
[msgLabel setFrame:CGRectMake(15, 45, 290, msgSieheight)];
20、渐变字体Label
UIColor titleColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:@"btnpng"]];
NSString title = @"Setting";
UILabel titleLabel = [[UILabel alloc]
initWithFrame:CGRectMake(0, 0, 80, 44)];
titleLabeltextColor = titleColor;
titleLabeltext = title;
titleLabelfont = [UIFont boldSystemFontOfSize:20];
titleLabelbackgroundColor = [UIColor clearColor];
[selfview addSubview:titleLabel];
[titleLabel release];
21、Label添加边框
titleLabellayerborderColor = [[UIColor grayColor] CGColor];
titleLabellayerborderWidth = 2;
cocoscreator怎么访问button的label
Find
function在运行Turbo
C
debugger时用于显示规定的函数。
4
Refresh
display如果编辑窗口偶然被用户窗口重写了可用此恢复编辑窗口的内容。
11310
Break/watch菜单
按Alt+B可进入Break/watch菜单,
该菜单有以下内容,如图所示:
Add
watch:
向监视窗口插入一监视表达式。
2
Delete
watch:从监视窗口中删除当前的监视表达式。
3
Edit
watch:在监视窗口中编辑一个监视表达式。
4
Remove
all
:watches从监视窗口中删除所有的监视表达式。
5
Toggle
breakpoint:对光标所在的行设置或清除断点。
6
Clear
all
breakpoints:清除所有断点。
7
View
next
breakpoint:将光标移动到下一个断点处。
1 QLabel::fontMetrics()width(QString s): 获取字符串s的总像素宽度。
int QFontMetrics::width ( const QString & text, int len = -1 ) const
Returns the width in pixels of the first len characters of text If len is negative (the default), the entire string is used
Note that this value is not equal to boundingRect()width(); boundingRect() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn
See also boundingRect()
2 QLabel::fontMetrics()height(): 获取字体的高度。
int QFontMetrics::height () const
Returns the height of the font
This is always equal to ascent()+descent()+1 (the 1 is for the base line)
See also leading() and lineSpacing()
3 QLabel::fontMetrics()lineSpacing(): 获取字体的高度,包括文字的实际宽度和行距。
4 QLabel::fontMetrics()leading(): 行间距
int QFontMetrics::leading () const
Returns the leading of the font
This is the natural inter-line spacing
See also height() and lineSpacing()
其他函数参见QT 的 QFontMetrics Class Reference
int QFontMetrics::lineSpacing () const
Returns the distance from one base line to the next
This value is always equal to leading()+height()
See also height() and leading()
以上就是关于关于objectiveC 中的 label全部的内容,包括:关于objectiveC 中的 label、Cocos creator label.string设置后怎么获取新设置的文字的size、通过qss设置qlabel的字体大小,为什么获取到qlabel的字符串宽度一样等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)