【问题标题】:How to make image view as button in Objective-C?如何在Objective-C中将图像视图作为按钮?
【发布时间】:2015-07-18 07:15:50
【问题描述】:

例如: 集合视图有四个图像,用户触摸任何单元格意味着它想去另一个视图控制器。给我一些想法的朋友。

以这张图片为例,如果用户点击 chrome 图片意味着它会转到另一个视图控制器。

【问题讨论】:

标签: objective-c uiimageview uicollectionview uitouch uievent


【解决方案1】:

新建UIButton,然后在其上使用setImage方法设置图像。将标题留空。

【讨论】:

  • 有没有可能在uiimage视图中使用touch up inside方法
【解决方案2】:

将此代码用于 objc:

-(void)viewDidLoad {

UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[imageview setImage:[UIImage imageNamed:@"image.png"]];
[imageview setUserInteractionEnabled:YES];

UITapGestureRecognizer *singleTap =  [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapping:)];
[singleTap setNumberOfTapsRequired:1];
[imageview addGestureRecognizer:singleTap];

[self.view addSubview:imageview];
}

【讨论】:

    猜你喜欢
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-26
    • 2014-02-07
    • 2015-11-04
    • 2011-10-10
    • 2016-10-18
    相关资源
    最近更新 更多