UIImageview

- (void)viewDidLoad {
    [super viewDidLoad];
//    页面颜色
    self.view.backgroundColor = [UIColor yellowColor];
    [[UIScreen mainScreen]bounds];
//    实例化
    UIImageView *ImageView = [[UIImageView  alloc]initWithFrame:CGRectMake(10, 20, 200, 100)];
//    实例并提取图片
    UIImageView *ImageViewI = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"6"]];
//    实例后提取图片
    ImageView.image =[UIImage imageNamed:@"1" ];
    ImageViewI.frame =CGRectMake(10,125 , 350, 100);
//    同时实力两张图片
    _ImageViewII =[[UIImageView alloc]initWithImage:[UIImage  imageNamed:@"11"] highlightedImage:[UIImage imageNamed:@"7"]];
    _ImageViewII.frame =CGRectMake(10, 300,350, 100);
    [ self.view  addSubview : ImageView ];
    [ self.view  addSubview : ImageViewI ];
    [ self.view  addSubview : _ImageViewII ];
//    设置按钮
    UIButton *Button = [[UIButton  alloc]initWithFrame:CGRectMake(40, 400, 100, 40)];
    [Button setTitle:@"高亮切换" forState: UIControlStateNormal];
    Button.backgroundColor = [UIColor  purpleColor];
    [Button addTarget:self action:@selector(gaoliang) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Button];
//    设置图片决定字符大小;方法的设定;
    _ImageViewIII= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"6"]];
    _ImageViewIII.frame = CGRectMake(250, 500, 150, 100);
    [self.view addSubview:_ImageViewIII];
    UIButton *buttonBig = [[UIButton alloc]initWithFrame:CGRectMake(200,500 , 50, 50)];
    buttonBig.backgroundColor = [UIColor redColor];
    [buttonBig setTitle:@"放大" forState:UIControlStateNormal];
    [buttonBig addTarget:self action:@selector(Big) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonBig];
    UIButton *buttonSmall = [[UIButton alloc]initWithFrame:CGRectMake(200, 550, 50, 50)];
    buttonSmall.backgroundColor = [UIColor blackColor];
    [buttonSmall setTitle:@"缩小" forState:UIControlStateNormal];
    [buttonSmall addTarget:self action:@selector(Small) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonSmall];
    _ImageViewIIII = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 200)];
    [self.view addSubview:_ImageViewIIII];
    
    
    
    _ImageViewset = [[UIImageView alloc]initWithFrame:CGRectMake(10, 500, 140, 100)];
    _ImageViewset.image = [UIImage imageNamed:@"17"];
    [self.view addSubview:_ImageViewset];
    UIButton *ButtonUp = [[UIButton alloc]initWithFrame:CGRectMake(10, 600,80, 50)];
    ButtonUp.backgroundColor = [UIColor redColor];
    [ButtonUp setTitle:@"变大" forState:UIControlStateNormal];
    [ButtonUp addTarget:self action:@selector(bianda)
     forControlEvents:UIControlEventTouchUpInside];
     ButtonUp.backgroundColor = [UIColor purpleColor];
    
    
    UIButton *ButtonDown = [[UIButton alloc]initWithFrame:CGRectMake(80, 600,70, 50)];
    ButtonDown.backgroundColor = [UIColor blackColor];
    [ButtonDown setTitle:@"变小" forState:UIControlStateNormal];
    [ ButtonDown addTarget:self action:@selector(suoxiao) forControlEvents:UIControlEventTouchUpInside ];
    [self.view addSubview:ButtonUp];
    [self.view addSubview:ButtonDown];
}

- ( void )gaoliang{

    if (_ImageViewII.highlighted ==YES) {
        _ImageViewII.highlighted =NO;
    } else {
        _ImageViewII.highlighted =YES;
    }


}
- (void)Big{
   _ImageViewIII.transform =CGAffineTransformMakeScale(4.5, 4.5);
}
- ( void )Small{
    _ImageViewIII.transform =CGAffineTransformMakeScale(2.3, 4.5);
}
- ( void )bianda{
    CGRect bonus = _ImageViewIIII.bounds;
    bonus.size.width += 50;
    bonus.size.height += 50;
    _ImageViewIIII.bounds = bonus;
}

- ( void )suoxiao{
    NSLog(@"suoxiao");
    CGRect frame= _ImageViewset.frame;
    NSLog(@"------%f",frame.size.width);
    frame.size.height -= 30;
    frame.size.width -= 30;
    _ImageViewset.frame=frame;
    NSLog(@"++++%f",frame.size.width);
}


你可能感兴趣的:(UIImageview)