Skip to content

Add MUToast buttons

Compare
Choose a tag to compare
@MoveUpwardsDev MoveUpwardsDev released this 27 Jun 15:34
· 247 commits to master since this release

usage

First you can define the layout basics using UIAppearance

MUToast.appearance().displayDuration = 0
MUToast.appearance().cornerRadius = 4
MUToast.appearance().titleColor = .white
MUToast.appearance().backgroundColor = .black
MUToast.appearance().indicatorColor = .red
MUToast.appearance().indicatorWidth = 10
MUToast.appearance().detailColor = .white

MUButton.appearance().borderWidth = 2
MUButton.appearance().cornerRadius = 4.0

Then you customize your toast view

let toast = MUToast()
toast.icon = #imageLiteral(resourceName: "reddit")
toast.buttonHeight = 30.0
toast.spacing = 8
toast.buttonSpacing = 16
toast.displayPosition = .bottom
toast.title = "Sorry, can't reach Reddit"
toast.titleFont = .boldSystemFont(ofSize: 18)
toast.detail = "Add multiple line detail text if needed"
toast.detailFont = .systemFont(ofSize: 14)

Then init buttons objects you want to add in your toast

let cancel = MUButton()
cancel.title = "CANCEL"
cancel.titleFont = .boldSystemFont(ofSize: 14)
cancel.buttonBackgroundColor = .clear
cancel.borderColor = .orange

let okay = MUButton()
okay.title = "OKAY"
okay.titleFont = .boldSystemFont(ofSize: 14)
okay.buttonBackgroundColor = .red
okay.borderColor = .red

Add button along with an options closure that will be triggered every time the button get tapped

toast.add(view: cancel) { (button, index) in
    print("Button at index \(index) did tap")
}
toast.add(view: okay) { (button, index) in
    print("Button at index \(index) did tap")
}

Then show your toast

toast.show(in: vc, onTap: {
    print("toast has been tapped")
}, completion: { dismiss in
    print("toast has been dismissed > ", dismiss)
})