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