Tuesday, 7 March 2017

NavigationBar : 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 label1 : UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
      
        // create label
        let navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 36, width: 320, height: 44))
        self.view.addSubview(navBar);
        let navItem = UINavigationItem(title: "SomeTitle");
        let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: nil, action: "doneButton:");
        navItem.rightBarButtonItem = doneItem;
        let leftItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: nil, action: "leftButton:");
        navItem.leftBarButtonItem = leftItem;
        
        navBar.setItems([navItem], animated: false);
        view.addSubview(navBar)
        
        label1 = UILabel()
        label1.frame = CGRect(x: 50, y: 100, width: 300, height: 36)
        label1.text = "Default"
        view.addSubview(label1)
        
     }

    func doneButton(sender : AnyObject)
 {
  label1.text = "Done button"
    }

    func leftButton(sender1 : UIButton)
    {
        label1.text = "Left button"
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}


No comments:

Post a Comment