_noLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 40)];
_noLabel.text = @"1/5";
_noLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:_noLabel];
CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
定义 Label 的 x、y、宽、高,数值是浮点
_noLabel.textAlignment = NSTextAlignmentCenter;
定义文本的对齐方式。些处为剧中对齐
[self.view addSubview:_noLabel];
self.view 相当于flash中的舞台
addSubview:_noLabel 将 _noLabel 添加到舞台中,让对象显示
CGFloat imageW = 200;
CGFloat imageH = 200;
CGFloat imageX = (self.view.bounds.size.width - imageW) * 0.5;
CGFloat imageY = CGRectGetMaxY(self.noLabel.frame) + 20;
CGFloat: 浮点值的基本类型
CGPoint: 表示一个二维坐标系中的点
CGSize: 表示一个矩形的宽度和高度
CGRect: 表示一个矩形的位置和大小
self.view.bounds.size.width 舞台(屏幕显示区域)的宽度
CGRectGetMaxY(self.noLabel.frame)
获取 noLabel 的高度
_iconImage.image = [UIImage imageNamed:@"biaoqingdi"];
[UIImage imageNamed:@"biaoqingdi"]; 获取图片文件
_leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
CGFloat centerX = self.iconImage.frame.origin.x * 0.5;
CGFloat centerY = self.iconImage.center.y;
_leftButton.center = CGPointMake(centerX, centerY);
[_leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];
[_leftButton setBackgroundImage:[UIImage imageNamed:@"left_highLighted"] forState:UIControlStateHighlighted];
[self.view addSubview:_leftButton];
_leftButton.tag = -1;
[_leftButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
self.iconImage.frame.origin.x 获取 iconImage 的 X 坐
self.iconImage.center.y 获取 iconImage 中心点的 Y坐标
_leftButton.center = CGPointMake(centerX, centerY);
设置 _leftButton 中心点的坐标,也就是给 _leftButton 的中心点赋值。
setBackgroundImage 给按钮添加背影图片。
UIImage imageNamed:@"left_normal"];图片的位置和名称
forState:UIControlStateNormal 按钮的状态
[_leftButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
给按钮添加点击事件
addTarget 对象
action:@selector(clickButton:)
@selection 选择状态
clickButton 不带参数事件
clickButton: 带参数事件
forControlEvents:UIControlEventTouchUpInside
触碰事件
_leftButton.tag = -1;
给按钮添加标签
-(NSArray *)imageList
{
NSLog(@"读取图像信息");
if (_imageList == nil) {
NSLog(@"实例化数组");
// "包" Bundle [NSBundel mainBundle] 编译安装之后对应的程序包
NSString *path = [[NSBundle mainBundle] pathForResource:@"imageList" ofType:@"plist"];
NSLog(@"%@",path);
// 在 OC中,ContentsOfFile.通常需要完整的路径
_imageList = [NSArray arrayWithContentsOfFile:path];
NSLog(@"%@",_imageList);
}
return _imageList;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"imageList" ofType:@"plist"];
获取 plist的路径
pathForResource:@"imageList" 得到 plist 的文件名
<pre name="code" class="objc">ofType:@"plist" 指定后缀名为 "plist"
_imageList = [NSArray arrayWithContentsOfFile:path];
将 plist 中的数据 添加到数组中
self.iconImage.image = [UIImage imageNamed:self.imageList[self.index][@"name"]];
self.descLabel.text = self.imageList[self.index][@"desc"];
读取 数组跌name和desc信息