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/               
      *************************************************************************/

  • 相关阅读:
    Android 基于Message的进程间通信 Messenger完全解析
    Android获取TextView显示的字符串宽度
    关于移动App的五个提问
    Android 结合实例学会AsyncTask的用法
    提高 Android 代码质量的4个工具
    高效开发Android App的10个建议
    移动5年 Android生态系统的演进
    最受欢迎的游戏引擎集结号:跨平台篇
    Java程序员转Android开发必读经验分享
    8 个最优秀的 Android Studio 插件
  • 原文地址:https://www.cnblogs.com/submarinex/p/2802015.html
Copyright © 2011-2022 走看看