यह एक UIActionSheet
है। आईफोन पर, यह नीचे से एनिमेट करता है। आईपैड पर यह एक पॉपओवर में दिखाई देता है।
आप एक बटन के प्रेस पर यह कर रहे हैं मान लिया जाये:
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil
delegate: self
cancelButtonTitle: nil
destructiveButtonTitle: nil
otherButtonTitles: @"Take Photo",
@"Choose Existing Photo", nil];
[actionSheet showFromRect: button.frame inView: button.superview animated: YES];
में iOS8 +, आप नए UIAlertController
वर्ग का उपयोग करना चाहिए:
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil
message: nil
preferredStyle: UIAlertControllerStyleActionSheet];
[alertController addAction: [UIAlertAction actionWithTitle: @"Take Photo" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// Handle Take Photo here
}]];
[alertController addAction: [UIAlertAction actionWithTitle: @"Choose Existing Photo" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// Handle Choose Existing Photo here
}]];
alertController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController * popover = alertController.popoverPresentationController;
popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
popover.sourceView = sender;
popover.sourceRect = sender.bounds;
[self presentViewController: alertController animated: YES completion: nil];
या स्विफ्ट
में
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
alertController.addAction(UIAlertAction(title: "Take Photo", style: .Default, handler: { alertAction in
// Handle Take Photo here
}))
alertController.addAction(UIAlertAction(title: "Choose Existing Photo", style: .Default, handler: { alertAction in
// Handle Choose Existing Photo
}))
alertController.modalPresentationStyle = .Popover
let popover = alertController.popoverPresentationController!
popover.permittedArrowDirections = .Up
popover.sourceView = sender
popover.sourceRect = sender.bounds
presentViewController(alertController, animated: true, completion: nil)
स्रोत
2012-05-24 19:56:13
क्या मैं इसे पॉपओवर व्यू में जोड़ता हूं? – ManOx
नहीं, बस यूआईएक्शनशीट शो में से एक का उपयोग करें ... तरीकों से। उदाहरण के लिए मेरा अद्यतन उत्तर देखें –
ठीक है और 1 और सवाल, मैं बटन पर ईवेंट हैंडलर कैसे सेट अप करूं? – ManOx