首页 > 移动平台 > 详细

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

时间:2016-03-09 23:45:36      阅读:467      评论:0      收藏:0      [点我收藏+]
在.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
 
 
 
 

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

原文:http://www.cnblogs.com/guiyangxueyuan/p/5260013.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!