How do customize actionsheet default when click button upload file on webview in ios app with swift?
Asked
Active
Viewed 3,076 times
0
-
1Possible duplicate of [How to customize UIActionSheet? iOS](https://stackoverflow.com/questions/17946358/how-to-customize-uiactionsheet-ios) – Cosmos Man Jul 20 '18 at 10:05
-
i don't think so. Actionsheet in my question is default, now i want to add a few option , i don't know how to do it. – Michael Jul 20 '18 at 10:55
-
@Michael, Apple provides you with default native behavior, anything else is custom and someone build it from the ground up, since `UIAlertAction` is not a subview of `UIView` then what you are asking for need to be build from scratch or you can look it up in GitHub. – AaoIi Jul 20 '18 at 13:15
1 Answers
1
Here the action sheet variable is the actionsheet in question. You can give it a title and a message. You then have to create a variable for each action that you want with the UIAlertAction initializer, in there handlers, you can add what each action should do.
You then need to assign the actions to the Action Sheet that you created. Finally, you should present the action sheet from the view controller that is in charge of presenting it.
The following does what I'm trying to explain.
let actionSheet = UIAlertController(title: "My Action Sheet", message: "My Action Sheet Message", preferredStyle: .actionSheet)
let action1 = UIAlertAction(title: "Action 1", style: .default) { (action) in
//Perform any actions specific to action 1 in your class
}
let action2 = UIAlertAction(title: "Action 2", style: .default) { (action) in
//Perform any actions specific to action 2 in your class
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) //Will just dismiss the action sheet
actionSheet.addAction(action1)
actionSheet.addAction(action2)
actionSheet.addAction(cancelAction)
present(actionSheet, animated: true, completion: nil)

Alan S
- 594
- 3
- 13
-
thank you about your answer, but i want to add a few option to actionsheet defaul when click uploadfile on webview – Michael Jul 21 '18 at 02:48
-
@Michael if my response helped you please set it as the accepted answer – Alan S Jul 23 '18 at 09:29