UIView UIButton UIImageView 添加事件
2015-06-02 22:11
615 查看
UIButton 添加事件
UIButton *aButton = [UIButton
buttonWithType:UIButtonTypeCustom];
aButton.frame =
CGRectMake(50,
50, 80,
40);
[aButton setBackgroundColor:[UIColor
grayColor]];
[aButton
setAlpha:0.4];
[aButton.layer
setMasksToBounds:YES];
[aButton.layer
setCornerRadius:10.0];
//设置矩形四个圆角半径
[aButton.layer
setBorderWidth:1.0];
//边框宽度
//添加事件的代码 使用UITapGestureRecognizer, 需要实现的是doImgClick
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImgClick)];
//加入到aImageView上。
[aImageView
addGestureRecognizer:singleTap];
[aView
addSubview:aButton];
实现 doImgClick
- (void)doClick:(UIButton *)button
{
NSLog(@"do Click = %@", button);
NSString *title = [button
titleForState:UIControlStateNormal];
NSLog(@"After Click = %@", title);
}
给图片添加事件,首先要在UIImageView上添加一个图片
UIImageView *bImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(30,
240, 60,
60)];
[bImageView setBackgroundColor:[UIColor
greenColor]];
[bImageView
setAlpha:0.8];
[bImageView
setHighlighted:YES];
[bImageView setHighlightedImage:[UIImage
imageNamed:@"0.png"]];
[bImageView setUserInteractionEnabled:YES];
//添加事件代码
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImgClick)];
[bImageView
addGestureRecognizer:singleTap1];
[bImageView
addSubview: aImageView];
实现 doImgClick 该方法是点击后,调到另外一个UIView上。
- (void)doImgClick
{
UIView *aView = [[UIView
alloc] initWithFrame:CGRectMake(0,
0, 400,
500)];
[aView setBackgroundColor:[UIColor
greenColor]];
[aView setClipsToBounds:YES];
[self.window
addSubview:aView];
UIImageView *aImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
0, 400,
500)];
[aImageView setBackgroundColor:[UIColor
greenColor]];
//[aImageView setAlpha:0.8];
[aImageView
setHighlighted:YES];
[aImageView setHighlightedImage:[UIImage
imageNamed:@"a.png"]];
UIImageView *bImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
0, 60,
60)];
[bImageView setBackgroundColor:[UIColor
greenColor]];
[bImageView
setHighlighted:YES];
[bImageView setHighlightedImage:[UIImage
imageNamed:@"0.png"]];
[bImageView setUserInteractionEnabled:YES];
//这里我实现了一个 跳到另一个UIView的方法
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImg1Click)];
[bImageView
addGestureRecognizer:singleTap1];
[aView
addSubview:aImageView];
[aView
addSubview:bImageView];
NSLog(@"do Click");
}
UIButton *aButton = [UIButton
buttonWithType:UIButtonTypeCustom];
aButton.frame =
CGRectMake(50,
50, 80,
40);
[aButton setBackgroundColor:[UIColor
grayColor]];
[aButton
setAlpha:0.4];
[aButton.layer
setMasksToBounds:YES];
[aButton.layer
setCornerRadius:10.0];
//设置矩形四个圆角半径
[aButton.layer
setBorderWidth:1.0];
//边框宽度
//添加事件的代码 使用UITapGestureRecognizer, 需要实现的是doImgClick
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImgClick)];
//加入到aImageView上。
[aImageView
addGestureRecognizer:singleTap];
[aView
addSubview:aButton];
实现 doImgClick
- (void)doClick:(UIButton *)button
{
NSLog(@"do Click = %@", button);
NSString *title = [button
titleForState:UIControlStateNormal];
NSLog(@"After Click = %@", title);
}
给图片添加事件,首先要在UIImageView上添加一个图片
UIImageView *bImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(30,
240, 60,
60)];
[bImageView setBackgroundColor:[UIColor
greenColor]];
[bImageView
setAlpha:0.8];
[bImageView
setHighlighted:YES];
[bImageView setHighlightedImage:[UIImage
imageNamed:@"0.png"]];
[bImageView setUserInteractionEnabled:YES];
//添加事件代码
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImgClick)];
[bImageView
addGestureRecognizer:singleTap1];
[bImageView
addSubview: aImageView];
实现 doImgClick 该方法是点击后,调到另外一个UIView上。
- (void)doImgClick
{
UIView *aView = [[UIView
alloc] initWithFrame:CGRectMake(0,
0, 400,
500)];
[aView setBackgroundColor:[UIColor
greenColor]];
[aView setClipsToBounds:YES];
[self.window
addSubview:aView];
UIImageView *aImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
0, 400,
500)];
[aImageView setBackgroundColor:[UIColor
greenColor]];
//[aImageView setAlpha:0.8];
[aImageView
setHighlighted:YES];
[aImageView setHighlightedImage:[UIImage
imageNamed:@"a.png"]];
UIImageView *bImageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
0, 60,
60)];
[bImageView setBackgroundColor:[UIColor
greenColor]];
[bImageView
setHighlighted:YES];
[bImageView setHighlightedImage:[UIImage
imageNamed:@"0.png"]];
[bImageView setUserInteractionEnabled:YES];
//这里我实现了一个 跳到另一个UIView的方法
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(doImg1Click)];
[bImageView
addGestureRecognizer:singleTap1];
[aView
addSubview:aImageView];
[aView
addSubview:bImageView];
NSLog(@"do Click");
}
相关文章推荐
- vector ,deque 和 list
- iOS开发系列--UITableView全面解析
- UILabel自适应高度和自动换行
- iOS_UITextField 基本操作
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'yintingting_baisi/Info.plist'.
- Android Volley完全解析(三),定制自己的Request
- iOS_UIButton 简单操作
- iOS按钮UIButton常用属性总结
- UIScrollView代理方法
- easyui换主题,并记录在cookie.以及cookie作用域介绍
- java 的builder模式——设计思想
- .net mvc4 从客户端中检测到有潜在危险的 Request.Form 值
- IIC(Inter-Integrated Circuit)总线协议浅谈
- iOS开发UI篇—UITableview控件简单介绍
- Android Call requires API level 19 (current min is 11)
- OpenCV学习笔记(四十七)——VideoWriter生成视频流highgui
- 自定义UITableViewCell 上的多个按钮点击事件处理
- iOS-学习笔记-UI-第一天
- 6.2 视图UIView及视图控制器(UIViewController)
- ajax阻塞UI线程