How to hide title/message frame in a UIAlertController?

后端 未结 5 618
粉色の甜心
粉色の甜心 2020-12-24 05:02

When using a UIAlertController, if I want to present a UIActionSheet with an empty title and an empty message, the frame for the expected placement

相关标签:
5条回答
  • 2020-12-24 05:24

    When I create a UIAlertController with this code I don't have the title spacing.

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

    Are you passing in nil for the title and message or empty strings?

    0 讨论(0)
  • 2020-12-24 05:26

    Update Swift 4:

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

    Just need to pass nil to title and message params.

    0 讨论(0)
  • 2020-12-24 05:27

    If you want to change in run time depending on a certain case just write:

    actionController.title = nil
    actionController.message = nil

    0 讨论(0)
  • 2020-12-24 05:41

    In swift 2.2, you can use code below and I have also changed the color of signout action button

            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 讨论(0)
  • 2020-12-24 05:43

    UIAlertController *controller=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];//style check

    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)
    

    { //write to perform 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];
    
    0 讨论(0)
提交回复
热议问题