Monday, 6 March 2017

UIImageView Dynamic



//
//  ViewController.swift
//  TestApp1
//
//  Created by Divakar Singh on 3/1/17.
//  Copyright (c) 2017 Divakar Singh. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var img1 :UIImageView!
    var btn1 : UIButton!
    var btn2 : UIButton!
    var btn3 : UIButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // create Label
        img1 = UIImageView()
        img1.sizeToFit()
        img1.frame = CGRect(x: 10, y: 10, width: 200, height: 200)
        img1.image = UIImage(named: "images")
        img1.contentMode = UIViewContentMode.ScaleAspectFit
        img1.backgroundColor = UIColor.grayColor()
        view.addSubview(img1)
      
    
        // create switch 2
        btn1 = UIButton()
        btn1.frame = CGRect(x: 50, y: 300, width: 150, height: 36)
        btn1.setTitle("Change", forState: UIControlState.Normal)
        btn1.backgroundColor = UIColor.greenColor()
        btn1.addTarget(self, action: "changeImage:", forControlEvents: UIControlEvents.TouchUpInside)
        
        view.addSubview(btn1)
        // create switch 2
        btn2 = UIButton()
        btn2.frame = CGRect(x: 150, y: 300, width: 150, height: 36)
        btn2.setTitle("Opaque", forState: UIControlState.Normal)
        btn2.backgroundColor = UIColor.greenColor()
        btn2.addTarget(self, action: "opaqueImage:", forControlEvents: UIControlEvents.TouchUpInside)
        
        view.addSubview(btn2)
     }

    
    func changeImage(sender : UIButton)
    {
     img1.image = UIImage(named: "Screenshot")
    }
    func opaqueImage(sender : UIButton)
    {
        img1.alpha = 0.5
    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}


No comments:

Post a Comment