Tuesday, 28 February 2017

Dynamic Button -2 : ButtonType




//
//  ViewController.swift
//  ImageView
//
//  Created by Divakar Singh on 2/27/17.
//  Copyright (c) 2017 Divakar Singh. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var label1 : UILabel!
    var btn1 = UIButton.buttonWithType(UIButtonType.System) as UIButton
     var btn2 = UIButton.buttonWithType(UIButtonType.ContactAdd) as UIButton
    var btn3 = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as UIButton
    var btn4 = UIButton.buttonWithType(UIButtonType.InfoDark) as UIButton
    var btn5 = UIButton.buttonWithType(UIButtonType.InfoLight) as UIButton

    
    /*
    - Button - 1 is use here for single click
    - Button - 2 and 3 is for multiple button click same function
    */
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // creating text
        label1 = UILabel()
        label1.frame = CGRect(x: 100, y: 100, width: 500, height: 60)
        label1.text = "Default Text"
        view.addSubview(label1);
        
        // creating button-1
        btn1.sizeToFit()
        btn1.frame = CGRect(x: 150, y: 150, width: 120, height: 40)
        btn1.setTitle("Button 1", forState: UIControlState.Normal)
        btn1.backgroundColor = UIColor.purpleColor()
        view.addSubview(btn1)
        
        // creating button-2
        btn2.sizeToFit()
        btn2.frame = CGRect(x: 150, y: 200, width: 120, height: 40)
        btn2.setTitle("Button 2", forState: UIControlState.Normal)
        btn2.backgroundColor = UIColor.purpleColor()
        view.addSubview(btn2)
        
        // creating button-3
        btn3.sizeToFit()
        btn3.frame = CGRect(x: 150, y: 250, width: 120, height: 40)
        btn3.setTitle("Button 3", forState: UIControlState.Normal)
        btn3.backgroundColor = UIColor.purpleColor()
        view.addSubview(btn3)
        
        // creating button-4
        btn4.sizeToFit()
        btn4.frame = CGRect(x: 150, y: 300, width: 120, height: 40)
        btn4.setTitle("Button 4", forState: UIControlState.Normal)
        btn4.backgroundColor = UIColor.purpleColor()
        view.addSubview(btn4)
        
        // creating button-5
        btn5.sizeToFit()
        btn5.frame = CGRect(x: 150, y: 350, width: 120, height: 40)
        btn5.setTitle("clickto change in label", forState: UIControlState.Normal)
      
        
    }

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


}


No comments:

Post a Comment