1. 显示图片
1> UIImageView只能显示一种图片(图片默认会填充整个UIImageView) image\setImage:2> UIVutton能显示2种图片, 还能显示文字 setTitle: forState: *背景 (背景会填充整个UIButton) setBackrougImage: forState: *前置 (覆盖在背景上面的图片, 按照之前的尺寸显示) setImage: forState:2.点击事件
1> UIImageView默认是不能响应点击事件2> UIButton能响应点击事件: addTarget: action: forControlEvents:3.使用场合
1> UIImageView: 只显示图片, 不监听点击, 点击了图片后不做任何反应2> UIButton: 既显示图片, 又监听点击, 点击了图片后做一些其他的事情.4.继承结构
1> UIButton之所以能添加监听器来监听花四溅, 是因为它继承自UIControl2> UIImageView之所以不能添加监听器来监听事件, 那是因为它直接继承自UIView.
下面是例子:
UIImageView *image = [[UIImageView alloc]init]; image.image = [UIImage imageNamed:@"01"]; image.frame = CGRectMake(0, 0, 160, 240); [self.view addSubview:image]; UIButton *button = [[UIButton alloc]init]; [button setBackgroundImage:[UIImage imageNamed:@"01"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"06"] forState:UIControlStateNormal]; button.frame = CGRectMake(0, 250, 160, 240); [button addTarget:self action:@selector(sender) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:button];