Created
November 20, 2017 21:02
-
-
Save ramiresnas/6bef9142339f4557da8f5358c99c532f to your computer and use it in GitHub Desktop.
Navegação entre meses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class NavigationMonth{ | |
var current = Date() | |
var next : Date{return Calendar.current.date(byAdding: .month, value: 1, to: current)!} | |
var before : Date{return Calendar.current.date(byAdding: .month, value: -1, to: current)!} | |
init() {} // deve possuir um inicializador em branco | |
init(date : Date) { | |
current = date | |
} | |
} | |
//exemplo de implemantacao | |
let dateFormater = DateFormatter() | |
dateFormater.dateFormat = "MMMM" | |
var month = NavigationMonth() | |
//altere para que seja sua @IBAction no butao 'avancar' | |
func next() -> String{ | |
let nextMonthString = dateFormater.string(from: month.next) | |
month = NavigationMonth(date: month.next) | |
return nextMonthString | |
} | |
//altere para que seja sua @IBAction no butao 'voltar' | |
func before() -> String{ | |
let beforeMonthString = dateFormater.string(from: month.before) | |
month = NavigationMonth(date: month.before) | |
return beforeMonthString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment