mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
1.7 KiB
1.7 KiB
Typical use
Create an instance of MDCActionSheetController and add actions to it. You can now
present the action sheet controller.
Swift
let actionSheet = MDCActionSheetController(title: "Action Sheet",
message: "Secondary line text")
let actionOne = MDCActionSheetAction(title: "Home",
image: UIImage(named: "Home"),
handler: { print("Home action" })
let actionTwo = MDCActionSheetAction(title: "Email",
image: UIImage(named: "Email"),
handler: { print("Email action" })
actionSheet.addAction(actionOne)
actionSheet.addAction(actionTwo)
present(actionSheet, animated: true, completion: nil)
Objective-C
MDCActionSheetController *actionSheet =
[MDCActionSheetController actionSheetControllerWithTitle:@"Action sheet"
message:@"Secondary line text"];
MDCActionSheetAction *homeAction =
[MDCActionSheetAction actionWithTitle:@"Home"
image:[UIImage imageNamed:@"ic_home"]
handler:nil];
MDCActionSheetAction *favoriteAction =
[MDCActionSheetAction actionWithTitle:@"Favorite"
image:[UIImage imageNamed:@"ic_favorite"]
handler:nil];
[actionSheet addAction:homeAction];
[actionSheet addAction:favoriteAction];
[self presentViewController:actionSheet animated:YES completion:nil];