이것은 UIActionSheet
이다. iPhone에서는 아래에서부터 움직입니다. iPad에서는 popover에 나타납니다.
당신이 버튼을 누르면에이 일을하고 가정 :
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)
그냥 Popover보기에 추가합니까? – ManOx
아니요. UIActionSheet showFrom ... 메서드 중 하나를 사용하십시오. 예를 들어 업데이트 된 답변보기 –
좋아요. 질문 1 개만 추가하면 단추에 이벤트 처리기를 어떻게 설정합니까? – ManOx