Creating iPhone Pop-up Menu Similar to Mail App Menu

后端 未结 7 1316
野趣味
野趣味 2020-12-01 05:52

I\'d like to create a pop-up menu similar to the one found in the mail app when you want to reply to a message. I\'ve seen this in more than one application so I wasn\'t su

相关标签:
7条回答
  • 2020-12-01 06:29

    To everybody who is looking for a solution in Swift:

    1. Adopt UIActionSheetDelegate protocol

    2. Create and show the ActinSheet:

      let sheet: UIActionSheet = UIActionSheet()
      
      sheet.addButtonWithTitle("button 1")
      sheet.addButtonWithTitle("button 2")
      sheet.addButtonWithTitle("button 3")
      sheet.addButtonWithTitle("Cancel")
      sheet.cancelButtonIndex = sheet.numberOfButtons - 1
      sheet.delegate = self
      sheet.showInView(self.view)
      
    3. The delegate function:

      func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
      switch buttonIndex{
          case 0:
              NSLog("button1");
          case 1:
              NSLog("button2");
          case 2:
              NSLog("button3");
          case actionSheet.cancelButtonIndex:
              NSLog("cancel");
              break;
          default:
              NSLog("blub");
              break;
        }
      }
      
    0 讨论(0)
提交回复
热议问题