Wednesday, November 9, 2016

iPhone - Timer App Use of Navigation Bar, ToolBar and Barbuttons

Dear All....

Hello , Today i am uploading a Timer App in which u found the use of Navigation Bar , ToolBar and Buutons on these.


navigation bar appears at the top of an app screen, below the status bar, and enables navigation through a series of hierarchical app screens. 

The toolbar on the bottom of the Home screen appears on every page. You can place any icons on the toolbar that you want. 

Navigation Bat Buttons -  The Buttons which is used to perform some actions added on Navigation Bar / ToolBar

I m using Xcode 7.3 as a IDE and Swift as a programming language.

Few steps are.....

Step - 1. Launch your Xcode
Step - 2. Create a new project with Single View App options
Step - 3. Design whatever you want to add as a UI Component on Main.storyboard
Step - 4. Add Navigation Bar , ToolBar and  Bar Buttons as shown in layout 

            4.1 : Play Button will start the Timer
            4.2 : Pause Button will stop at the Current  Value
            4.3 : Refresh Button will reset from Beginning Step - 5. Add Appropriate code in this controller file.
Step - 6 . Select Emulator as you wish and run the app.



A. Output will be like ..... 




B. Swift code is as


import UIKit

class ViewController: UIViewController  {

    var timer = NSTimer()
    
    var time = 0
    
    @IBOutlet var timeLabel: UILabel!
    func increaseTime()
    {
        time += 1
        timeLabel.text = String(time)
    }
    
    @IBAction func playButton(sender: AnyObject) {
    
       timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(increaseTimer),  userInfo: nil, repeats: true)
        //timer =  NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("increaseTime"), userInfo: nil, repeats: true) Below Swift2.2
    }
    
    
    @IBAction func stopButton(sender: AnyObject) {
    
        timer.invalidate()
        time = 0
        timeLabel.text = " 0 "
    }
    
    @IBAction func pauseBut(sender: AnyObject) {
        timer.invalidate()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
   

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


}



No comments:

Post a Comment