#import
"LabelTestViewController.h"
@implementation
LabelTestViewController
/*
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
*label1 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 20.0
, 200.0
, 50.0
)];
UILabel
*label2 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 80.0
, 200.0
, 50.0
)];
UILabel
*label3 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 140.0
, 200.0
, 50.0
)];
UILabel
*label4 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 200.0
, 200.0
, 50.0
)];
UILabel
*label5 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 260.0
, 200.0
, 50.0
)];
UILabel
*label6 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 320.0
, 200.0
, 50.0
)];
UILabel
*label7 = [[UILabel
alloc
]initWithFrame
:CGRectMake
(50.0
, 380.0
, 200.0
, 50.0
)];
//设置显示文字
label1.text
= @"label1"
;
label2.text
= @"label2"
;
label3.
text
=
@"label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--";
label4.
text
=
@"label4--label4--label4--label4--";
label5.
text
=
@"label5--label5--label5--label5--label5--label5--";
label6.text
= @"label6"
;
label7.text
= @"label7"
;
//设置字体:粗体,正常的是 SystemFontOfSize
label1.font
= [UIFont
boldSystemFontOfSize
:20
];
//设置文字颜色
label1.textColor
= [UIColor
orangeColor
];
label2.textColor
= [UIColor
purpleColor
];
//设置文字位置
label1.textAlignment
= UITextAlignmentRight
;
label2.
textAlignment
=
UITextAlignmentCenter;
//设置字体大小适应label宽度
label4.
adjustsFontSizeToFitWidth =
YES
;
//设置label的行数
label5.numberOfLines
= 2
;
UIlabel.backgroudColor=[UIColor clearColor]; //可以去掉背景色
//设置高亮
label6.highlighted
= YES
;
label6.
highlightedTextColor = [
UIColor orangeColor
];
//设置阴影
label7.shadowColor
= [UIColor
redColor
];
label7.shadowOffset
= CGSizeMake
(1.0
,1.0
);
//
设置是否能与用户进行交互
label7.
userInteractionEnabled =
YES
;
//设置label中的文字是否可变,默认值是YES
label3.enabled
= NO
;
//
设置文字过长时的显示格式
label3.
lineBreakMode
=
UILineBreakModeMiddleTruncation;
//
截去中间
// typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip,//截去多余部分
// UILineBreakModeHeadTruncation,//截去头部
// UILineBreakModeTailTruncation,//截去尾部
// UILineBreakModeMiddleTruncation,//截去中间
// } UILineBreakMode;
//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
label4.
baselineAdjustment
=
UIBaselineAdjustmentNone;
// typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
// } UIBaselineAdjustment;
[self
.view
addSubview
:label1];
[self
.view
addSubview
:label2];
[self
.view
addSubview
:label3];
[self
.view
addSubview
:label4];
[self
.view
addSubview
:label5];
[self
.view
addSubview
:label6];
[self
.view
addSubview
:label7];
[label1 release
];
[label2 release
];
[label3 release
];
[label4 release
];
[label5 release
];
[label6 release
];
[label7 release
];
[super
viewDidLoad
];
}
/*
// 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.
[
super
didReceiveMemoryWarning];
// 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 {
[super
dealloc
];
}
@end
分享到:
相关推荐
UILabel 继承于 UIView 里的各种属性和方法使用
基于响应式编程和valist不定参原理,简化创建UILabel各种属性的代码!
动态设置label高度,及设置label顶端对齐等。
UILabel的删除线效果,主要是继承UiLabel类后重写方法得到 用法跟UILabelg一样,异常简单,多了一个 是否加上删除线的 属性而已
下面小编就为大家分享一篇iOS开发总结之UILabel常用属性介绍,具有很的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
产品特点支持接口构建器支持长按手势允许启用/禁用复制功能与项目中已经存在的所有UILabel对象一起使用安装可可豆安装UILabel + Copyable的最简单方法是通过 。 pod 'UILabel+Copyable' , '~> 2.0'老式的方式将...
主要介绍了iOS开发笔记--详解UILabel的相关属性设置,对初学者具有一定的参考价值,有需要的可以了解一下。
UILabel继承自UIView是iOS中使用非常频繁的一个视图控件一般用于显示文字。 一:基本使用 1.创建 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 64, 100, 30)]; [self.view addSubview:label...
在iOS编程中UILabel是一个常用的控件,下面分享一下UILabel的相关属性设置的方法。 很多学习iOS6编程都是从storyboard开始,用到UILabel时是将控件拖到storyboard中生成实现,如果想要在-(void)viewDidLoad中用代码...
一款使用简单的数字加减动画控件,支持UILabel、UIButton显示 1.支持UILable/UIButton/自定义文本控件的数字加减动画; 2.支持一般文本属性以及富文本属性的字体显示; 3.支持四种时间曲线函数动画:由慢到快再到慢...
该文档详细列出UITextField常用以及不常用的相关属性及如何进行设置,对大家掌握UITextField的用法很有帮助。
这使您能够使用CATextLayer的所有属性来创建一些简洁的文本效果。 CharacterText的灵感来自Secret和新的iOS8自动完成效果。 用法CharacterLabel可以代替UILabel使用。 您可以将CharacterLabel子类化,然后创建自己的...
源码CharacterText,CharacterText是一个可自定义文字效果的UILabel子类,使用NSLayoutManager来为字符串的每个字符定位CATextLayers。这样可以利用CATextLayer的属性来创建一些漂亮的文字效果,比如滑动视图后,...
用属性文本创建UILabel时,链接显示为蓝色并带有下划线,并且在大多数情况下,您不希望这样做。 尝试使它们简单地按照您期望的方式进行样式设置是非常尴尬和耗时的。 LinkLabel使这一切变得容易。 没有任何额外的...
这是一个标签UILabel的子类案例,源码BTLabel,BTLabel是UILabel的子类,能够通过竖直对齐(属性verticalAlignment)来控制文字来label中的位置。
目前有 3 个简单的属性(除了UILabel的): radius是我们在其上弯曲文本的弧的半径 rotation调整文本的旋转 textInside将文本设置为曲线内侧而不是外侧的曲线。 默认值为NO ,这意味着它在外面。 用法: 像往常...
TTTAttributedLabel UILabel替代品,支持属性,数据检测器,链接等TTTAttributedLabel是UILabel替代品,它提供了一种有效地呈现的简单方法。 另外,它还支持链接嵌入,既可以使用NSTextCheckingTypes自动进行链接...
它可以产生大量的效果,并使用简单的属性来设置。 您可以动态更改所有新属性。 安装 您只需将 LxLabel.h 和 LxLabel.m 拖到您的项目中。 支持 最低支持 iOS 版本:iOS 6.0 LxLabel * label = [[LxLabel alloc]...
CJLabelCJLabel继承自UILabel,在支持UILabel所有属性的基础上,还提供富文本、图文混排、任意view插入展示、自定义点击链点设置、长按(双击)唤起UIMenuController选择复制文本等功能。特性简介禁止使用-init初始...