xib 和 storyboard 区别
1. storyboard 是重量级的 : 他主要用来描述整体界面控制器,
管理控制器之间的跳转
2. xib 是轻量级的 : 描述局部界面,通常是 view
使用xib 文件:
简化代码, 通过拖拽的方式, 实现界面的搭建
1.在xib 文件中, 根据实际的需求摆放控件.
创建一个类文件: 为了方便为 xib 的控件 进行赋值
2.一般是继承自 UIView (需要哪一种, 就继承自谁)
3. 把创建的类文件 和 xib 进行关联 (设置标识符)
4. 在类文件中设置一个属性 : (接收模型数据, 方便为控件进行赋值)
--- 重写 属性 的set方法 (appModel)
一定要赋值 _appModel = appModel;
----加载xib 文件
为什么是 nib, 打包之后, 自动变成了-- .nib ---结尾的文件
UIView *appView = [[[NSBundle mainBundle] loadNibNamed:@"AppView" owner:nil options:nil] lastObject];
text 的 属性设置
nameLabel.
text
=
@"woshizhide"
;
// 设置字体大小
/**
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize; 默认字体
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; 加粗
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; 斜体
*/
// 设置字体大小
nameLabel. font = [ UIFont systemFontOfSize : 12 ];
// 设置对其方式
nameLabel. textAlignment = NSTextAlignmentCenter ;
// 设置背景颜色
nameLabel. backgroundColor = [ UIColor orangeColor ];
// 添加到 appView
// 设置字体大小
/**
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize; 默认字体
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; 加粗
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; 斜体
*/
// 设置字体大小
nameLabel. font = [ UIFont systemFontOfSize : 12 ];
// 设置对其方式
nameLabel. textAlignment = NSTextAlignmentCenter ;
// 设置背景颜色
nameLabel. backgroundColor = [ UIColor orangeColor ];
// 添加到 appView
[appView addSubview:nameLabel];
button 属性 的 设置
[Button setTitle: @"
下载
"
forState
:
UIControlStateNormal
];
// 设置button 的禁用状态下的文字
[Button setTitle:@"
已经下载
"
forState
:
UIControlStateDisabled
];
// 设置背景图片
[Button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
[Button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
// 设置button 中 title的字体
downButton.titleLabel.font = [UIFont systemFontOfSize:12];
// 把button 添加到 appView中
[appView addSubview:downButton];