zoukankan      html  css  js  c++  java
  • 在滚动视图里添加图像视图,在图像视图里添加按钮控件

     》》点击按钮“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 }

     。 


    /**************************************************************************
                      原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
      *************************************************************************/

  • 相关阅读:
    搭建james邮件服务器
    Spring -- AOP
    【RF库Collections测试】List Should Not Contain Duplicates
    【RF库Collections测试】Keep In Dictionary
    【RF库Collections测试】Insert Into List
    【RF库Collections测试】Get Index From List
    【RF库Collections测试】Get From List
    【RF库Collections测试】Count Values In List
    【RF库Collections测试】Get Slice From List
    【RF库Collections测试】Copy Dictionary
  • 原文地址:https://www.cnblogs.com/submarinex/p/2802015.html
Copyright © 2011-2022 走看看