Swift developed UIButton as a mask for image scaling

Source: Internet
Author: User

Many partners always think that the time to zoom picture is very troublesome, because do not know where to start, especially in the face of the new development language, in fact, there are many methods of image scaling, but original aim, that is frame, so, do not think so tall on. Here is an image scaling demousing masks, and interested partners can look at them.

//

Viewcontroller.swift

// Zoom of picture

//

Created by Yue technology on 15/1/15.

Copyright (c) year BSY. All rights reserved.

//


Import UIKit


Class Viewcontroller:uiviewcontroller {


var ImageView = Uiimageview ()

var button = UIButton ()

Override Func Viewdidload () {

Super.viewdidload ()

Initialize Uiimageview

var Imageview:uiimageview = Uiimageview (frame:cgrectmake (100, 100, 100, 100))

var image = UIImage (named: "1024")

Imageview.image = Image

Self.view.addSubview (ImageView)

Self.imageview = ImageView

Initialize UIButton(mask)

var Button:uibutton = Uibutton.buttonwithtype (uibuttontype.custom) as UIButton

var frame = Imageview.frame

Button.frame = Frame

Self.view.addSubview (Button)

Button.addtarget (Self, Action: "Changeimage:", ForControlEvents:UIControlEvents.TouchUpInside)

Self.button = button

Self.button.selected = False

}

initialization of the UIButton method implementation

Func Changeimage (Sender:uibutton) {

[UIView beginanimations ("", Context:nil)];

[UIView. Setanimationdelay (0.1)];

[UIView. Setanimationduration (0.5)];

self.button.selected =!sender.selected

if (self.button.selected = = True) {

Self.imageview.frame = Uiscreen.mainscreen (). Bounds

}else if (self.button.selected = = False) {

Self.imageview.frame = CGRectMake (100, 100, 100, 100)

[Uiview.commitanimations];}}

}





Swift developed UIButton as a mask for image scaling

Related Article

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.