UILabel:
NS_CLASS_AVAILABLE_IOS(2_0) @interface UILabel : UIView <NSCoding>
UILabel 继承自 UIView, 这意味着 UILabel可以使用 UIView所拥有的属性和方法, 通常使用UIView类的初始化方法
UILabel中常用的属性:
|
@property
(
nonatomic
,
copy
)
NSString
*text; —> UILabel对象中的文本
@property
(
nonatomic
,
retain
)
UIFont
*font; —> UILabel
对象
中文本的字体
@property
(
nonatomic
,
retain
)
UIColor
*textColor; —> UILabel
对象
中文本的颜色
@property
(
nonatomic
,
retain
)
UIColor
*shadowColor; —>
UILabel
对象
中文本阴影的颜色,默认为nil(无阴影)
@property
(
nonatomic
)
CGSize
shadowOffset;
@property
(
nonatomic
)
NSTextAlignment
textAlignment; —> 对齐方式
@property
(
nonatomic
)
NSLineBreakMode
lineBreakMode; —> 省略方式
@property
(
nonatomic
)
NSInteger
numberOfLines; —> 断行数, 0为没有限制, 以UILabel
对象
实际宽和高位界限
this determines the number of lines to draw and what to do when sizeToFit is called
|
注: 调用sizeToFit方法和设numberOfLines的先后顺序不同结果也是不一样的. 应该先设numberOfLines = 0, 再调用sizeToFit方法.
UITextField:
NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextInput, NSCoding>
继承关系: UITextField : UIControl : UIView : UIResponder : NSObject
通常使用
UIView类的初始化方法
UITextField中常用的属性:
|
@property
(
nonatomic
,
copy
)
NSString
*text; —> 属性意味着: 不仅可以赋值,还可以取值
@property
(
nonatomic
,
copy
)
NSAttributedString
*attributedText
NS_AVAILABLE_IOS
(
6
_0);
@property
(
nonatomic
,
retain
)
UIColor
*textColor;
@property
(
nonatomic
,
retain
)
UIFont
*font;
@property
(
nonatomic
)
NSTextAlignment
textAlignment; —> 对齐方式
@property
(
nonatomic
)
UITextBorderStyle
borderStyle;
@property
(
nonatomic
)
BOOL
clearsOnBeginEditing; —> 再次编辑是清空, YES为点击是清空, NO为点击时光标放在点击处, 默认为NO
@property
(
nonatomic
,
copy
)
NSString
*placeholder; —> 占位字符串,没有任何输入时,给出的提示字符串
|
UIImageView:
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView
UIImageView继承自UIView.
UIImageView中常用的属性:
|
@property
(
nonatomic
,
retain
)
UIImage
*image;
@property
(
nonatomic
,
retain
)
UIImage
*highlightedImage
NS_AVAILABLE_IOS
(
3
_0);
|
UIImageView的初始化方法:
|
- (
instancetype
)initWithImage:(
UIImage
*)image;
- (instancetype)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);
|
initWithImage需要一个UIImage类型的对象作为参数. UIImage可以用其便利构造器imageWithContentsOfFile:得到一个图片.
可以理解为: UIImage得到一个图片, 而UIImageView是装该图片的容器.
UIImage:
定义一个UIImage对象:
|
NSString
*imageName =
@"
图片名
”
; —> 获得文件名
NSString
*imagePath = [[
NSBundle
mainBundle
]
pathForResource
:imageName
ofType
:
@"png
”
]; —> 获得路径
UIImage
*aImage = [
UIImage
imageWithContentsOfFile
:imagePath]; —> 通过路径得到图像
|
注意
imageWithContentsOfFile: 和方法的区别
imageNamed:
- imageWithContentsOfFile: —> This method does not cache the image object.
- imageNamed: —> This method looks in the system caches for an image object with the specified name and returns that object if it exists.
所以
imageNamed: 加载时会缓存图片, 如果频繁引用一张图片, 则效率会比较高;
imageWithContentsOfFile: 不会将图片缓存到内存, 因此遇到大图片时用这个方法会更加省内存.
本文深入探讨了iOS开发中的Swift语言核心特性,包括类型系统、泛型、闭包和协程等内容,同时介绍了如何利用Swift的强大功能构建高效、安全的iOS应用。
1万+

被折叠的 条评论
为什么被折叠?



