在滚动视图里添加图像视图,在图像视图里添加按钮控件

 》》点击按钮“Button”》》》》

绿底的是一张图片(1.png),截自苹果文档。

第一个视图对应VC1:

VC1

 1 @synthesize scrollView = _scrollView;
 2 
 3 - (void)viewDidLoad
 4 {
 5     [super viewDidLoad];
 6     
 7     // 配置 UIImageView 对象
 8     UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
 9     imgView.userInteractionEnabled = YES;  // UIImageView 的 userInteractionEnabled 属性默认 "NO",因此默认情况下,添加在 UIImageView 中的 UIButton 将不发生触摸事件
10     
11     // 配置并添加 UIButton 对象
12     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
13     button.frame = CGRectMake(100, 80, 50, 60);
14     [button setTitle:@"Button" forState:UIControlStateNormal];
15     [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
16     [imgView addSubview:button];
17     
18     // 添加 UIImageView 对象
19     [self.scrollView addSubview:imgView];
20     
21     // 配置 UIScrollView 对象
22     self.scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
23     self.scrollView.scrollEnabled = YES;
24     self.scrollView.clipsToBounds = YES;
25     self.scrollView.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height);
26     
27 }
28 
29 - (IBAction)button:(id)sender
30 {
31     [self performSegueWithIdentifier:@"SeguePush1" sender:self];
32 }

 。 

转载于:https://www.cnblogs.com/submarinex/archive/2012/12/04/2802015.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值