---
title: "uiimageview uiscroll 图片的缩放"
author: "zheyiw"
date: "2012-09-25T18:01:09Z"
tags: ["Apple"]
categories: ["移动开发"]
slug: "uiimageview-uiscroll"
draft: false
lastmod: "2012-09-25T18:01:09Z"
id: 1685248
url: "https://zheyiw.iteye.com/blog/1685248"
---

```java


-(void)loadImage{    
    // Create a scroll view
    scrollView = [[uiscrollview alloc] initWithFrame:CGRectMake(0, 0, 320, 390)];
    scrollView.delegate = self;
    scrollView.bouncesZoom = YES;
    scrollView.backgroundColor = [uicolor whitecolor];
    
    CGFloat maximumWidth = 320;
    CGFloat totalHeight = 0.0;
    UIImage *image = [uiimage imagenamed:@"shopcart_no.png"];
    CGRect frame = CGRectMake(0, 0, 320, 390);
    imageView = [[uiimageview alloc] initWithFrame:frame];
    imageView.image = image;
    [imageview setcontentmode:uiviewcontentmodecenter];
    
    // Increment our maximum width & total height
    maximumWidth = MAX(maximumWidth, image.size.width);
    totalHeight += image.size.height;

    scrollView.minimumZoomScale = scrollView.frame.size.width / maximumWidth;
    scrollView.maximumZoomScale = 2.0;
    
    [scrollview addsubview:imageview];
    [self.view addsubview:scrollview];   
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}


```