Swift development-using UIButton as the mask board for image scaling, swiftuibutton

Source: Internet
Author: User

Swift development-using UIButton as the mask board for image scaling, swiftuibutton

Many partners always think that scaling images is very troublesome, because they do not know where to start, especially in the face of new development languages. In fact, there are many ways to scale images, but they are always different, that is frame. The following is an image scaling demo using the mask. If you are interested, you can take a look.

//

// ViewController. swift

// Resize the image

//

// Created by yueda Technology on 15/1/15.

// Copyright (c) 2015 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

}

// Initialize 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];}

}





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.