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

  • 相关阅读:
    unity c# 获取系统时间
    如果你想让继承MonoBehaviour的类变成Singleten
    关于程序员
    开始养成记录的习惯吧
    关于结构体的赋值问题
    数学中的集合,群,环,域
    励志
    [编程题] 进制均值
    javaEE 入门
    jsp内置对象2
  • 原文地址:https://www.cnblogs.com/submarinex/p/2802015.html
Copyright © 2011-2022 走看看