2015-04-21 47 views
31

當使用UIAlertController時,如果我想要顯示UIActionSheet空標題和空消息,標題和/或消息的預期放置幀將保留。如何在UIAlertController中隱藏標題/消息幀?

如何改變這種做法,我只是提出了一個ActionSheet,上面寫着:

設置
登出
取消 ?

謝謝!

UIAlertController example

回答

76

當我創建這個代碼UIAlertController我沒有標題的間距。

[UIAlertController alertControllerWithTitle:nil 
            message:nil 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

您是否將標題和消息或空字符串傳遞爲零?

+1

這很簡單。這就回答了我的問題。謝謝 – vlin

0

UIAlertController *控制器= [UIAlertController alertControllerWithTitle:@ 「」 消息:@ 「」 preferredStyle:UIAlertControllerStyleAlert]; //風格檢查

UIAlertAction *first = [UIAlertAction actionWithTitle: @"Login with Facebook" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) 
{ 
    //write to perform action 

}]; 


[controller addAction: first]; 



UIAlertAction *second = [UIAlertAction actionWithTitle: @"Guest User" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) 

{ //寫入執行操作

}]; 

[controller addAction:second]; 


UIAlertAction *third=[UIAlertAction actionWithTitle:@"Registered User" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) 


{ 
    //write to perform action 

}]; 

[controller addAction:third]; 

[self presentViewController: controller animated: YES completion: nil]; 
3

如果你想改變運行時間取決於某個特定情況,請寫:

actionController.title = nil
actionController.message = nil

0

在SWIFT 2.2,可以使用下面的代碼,我也改變了signout操作按鈕的顏色

 let actionSheet: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) 

    self.presentViewController(actionSheet, animated: true, completion: nil) 

    let settingsActionButton: UIAlertAction = UIAlertAction(title: "Settings", style: .Cancel) { action -> Void in 
     print("Settings Tapped") 
    } 

    reportActionSheet.addAction(settingsActionButton) 

    let signOutActionButton: UIAlertAction = UIAlertAction(title: "Signout", style: .Default) 
    { action -> Void in 
     //Clear All Method 
     print("Signout Tapped") 

    } 

    signOutActionButton.setValue(UIColor.redColor(), forKey: "titleTextColor") 

    actionSheet.addAction(signOutActionButton) 

    let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in 
     print("Cancel Tapped") 
    } 

    reportActionSheet.addAction(cancelActionButton) 
0

更新斯威夫特4:

let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) 

只需要傳遞無標題和消息參數。

謝謝