UILabel, UITextField, UIImageView

本文深入探讨了iOS开发中的Swift语言核心特性,包括类型系统、泛型、闭包和协程等内容,同时介绍了如何利用Swift的强大功能构建高效、安全的iOS应用。

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>

继承关系:   UITextFieldUIControl : 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: 不会将图片缓存到内存, 因此遇到大图片时用这个方法会更加省内存.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值