Uiimageview in iOS

Source: Internet
Author: User

1. Add picture     //There are two ways//     (1) General way//    Uiimageview  *imageview=[[uiimageview alloc]init];25//    UIImage *image=[uiimage imagenamed:@ "Minion"];26//    imageview.image=image;27//    imageview.frame= CGRectMake (0, 0, image.size.width, image.size.height);     (2) using the construction method of     UIImage *image=[uiimage imagenamed:@ "Minion"];31     _imageview=[[uiimageview alloc]initwithimage:image];32     //Call InitWithImage: Method, It creates the width of the ImageView and the width of the picture as high as

2. gesture Scaling (ScrollView)

(1). Set id<uiscrollviewdelegate> delegate proxy object for Uiscrollview

(2). Setting Minimumzoomscale: Minimum scale reduction

(3). Setting Maximumzoomscale: Maximum scale magnification

(4). Let the proxy object implement the following method to return the view control that needs to be scaled

-(UIView *)Viewforzoominginscrollview:(Uiscrollview *) ScrollView

The common methods associated with scaling are also

is being scaled when calling the

-(void)Scrollviewdidzoom:(Uiscrollview *) ScrollView

Call when Zoom is complete

-(void)scrollviewdidendzooming:(Uiscrollview *) ScrollView Withview:(UIView *) View Atscale :(float) scale

Code implementation:

-(void) Viewdidload {

[Super Viewdidload];

Add ScrollView

Uiscrollview *scrollview = [[Uiscrollview alloc]initwithframe:self. View. Bounds];

[Self. view Addsubview:scrollview];

Create ImageView

UIImage *image = [UIImage imagenamed:@ "big.jpg"];

Call Initwithimage: method, which creates the width of the ImageView and the width of the picture as high as

_imageview = [[uiimageview alloc]initwithimage:image];

[ScrollView Addsubview:_imageview];

//Set the range of scrolling

ScrollView. contentsize = image. size;

Set Proxy: The current controller becomes a proxy for ScrollView, you can use the properties and methods of ScrollView

You should call the [ScrollView Viewforzoominginscrollview:scrollview] notification to zoom the picture,

now Self is the controller itself acting as the agent of ScrollView , directly call the following viewforzooming method

ScrollView. delegate = self ;

ScrollView. Maximumzoomscale = 5.0;

ScrollView. Minimumzoomscale = 1.0;

}

-(UIView *) Viewforzoominginscrollview: (uiscrollview *) scrollview{

return _imageview;

}




Uiimageview in iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.