• iOS中用按钮NSbutton实现视图的放大与缩小功能


    在.h文件中
    首先声明需要的属性;
     
     
    在.m文件
    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];

         创建控制放大的按钮
        按钮类型
                  self.aButton=[UIButton buttonWithType:UIButtonTypeContactAdd];
       按钮的frame
                self.aButton.frame=CGRectMake(150, 500, 100, 100);
         按钮的背景图
        [self.aButton setBackgroundImage:[UIImage imageNamed:@"print1.png"] forState:UIControlStateNormal];

        。。。。。调用放大方法
        [self.aButton addTarget:self action:@selector(testBig) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.aButton];

        //控制缩小的按钮
        self.bButton=[UIButton buttonWithType:UIButtonTypeInfoLight];
        self.bButton.frame=CGRectMake(200, 500, 100, 100);
        [self.bButton setBackgroundImage:[UIImage imageNamed:@"print1.png"] forState:UIControlStateNormal];
        //    [self.Button setTitle:@"放大" forState:UIControlStateNormal];
        self.bButton.titleLabel.font=[UIFont systemFontOfSize:40 weight:30];
        [self.bButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        //调用缩小方法
        [self.bButton addTarget:self action:@selector(testSmall) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.bButton];
       
       
        self.aView=[[UIView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];
        self.aView.backgroundColor=[UIColor redColor];
        [self.view addSubview:self.aView];
        self.bView=[[UIView alloc]initWithFrame:CGRectMake(125, 225, 150, 150)];

        [self.view addSubview:self.bView];
     
        self.cView=[[UIView alloc]initWithFrame:CGRectMake(150, 250, 100, 100)];
        self.cView.backgroundColor=[UIColor blueColor];
        [self.view addSubview:self.cView];
       
    }
    //缩小方法的实现
    -(void)testSmall
    {
        //缩小
        if (self.aView.frame.size.width!=1&&self.bView.frame.size.width!=1&&self.aView.frame.size.width!=1) {
           
            self.aView.frame=CGRectInset(self.aView.frame, 10, 10);
            self.bView.frame=CGRectInset(self.bView.frame, 10, 10);
            self.cView.frame=CGRectInset(self.cView.frame, 10, 10);

        }
    }
    //放大方法的实现
    -(void)testBig
    {
        if (self.aView.frame.size.width!=self.view.frame.size.width&&self.bView.frame.size.width!=self.view.frame.size.width&&self.aView.frame.size.width!=self.view.frame.size.width)
        //放大
        { self.aView.frame=CGRectInset(self.aView.frame, -10, -10)
        self.bView.frame=CGRectInset(self.bView.frame, -10, -10);
        self.cView.frame=CGRectInset(self.cView.frame, -10, -10);
        }
    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end
     
     
     
     
  • 相关阅读:
    MP4文件格式
    ASP.net 学习路线(详细)
    H.264开源解码器评测
    H264编码 封装成MP4格式 视频流 RTP封包
    MP4介绍与基本AVC编码(x264)教程
    创建一个简单的WCF程序
    VUE 从零开始 学习笔记 一
    关于阿里云短信接口的使用
    对Ul下的li标签执行点击事件——如何获取你所点击的标签
    二逼程序员与苦逼程序员
  • 原文地址:https://www.cnblogs.com/guiyangxueyuan/p/5260013.html
Copyright © 2020-2023  润新知