标签: uialertcontroller

在Swift中设置UIAlertController的背景颜色

我正在使用new UIAlertController为我的应用程序实现各种选项菜单.我试图获得与UIAlertController我的应用程序其余部分的主题相匹配的背景颜色.我的应用程序的主题非常简单,包含工具栏和导航栏的蓝色/灰色背景颜色的白色文本,如下所示:

在此输入图像描述

但是,我在尝试让我UIAlertController遵守这个主题时遇到了一些麻烦.我进行了以下两次调用来设置文本和背景颜色:

uiAlertController.view.backgroundColor = UIColor(red: CGFloat(.17255), green: CGFloat(.24314), blue: CGFloat(.31373), alpha: CGFloat(1.0))
uiAlertController.view.tintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)

这改变了UIAlertController如下所示:

在此输入图像描述

文本已从默认的蓝色系统颜色更改为白色,但背景颜色不正确.我也尝试修改指定opacity(uiAlertController.view.opaque = true),但这也没有帮助.如何设置背景颜色以使其与导航栏和工具栏匹配?谢谢

interface-builder ios swift uialertcontroller

5
推荐指数
1
解决办法
7338
查看次数

从正在被解雇的模态呈现的控制器呈现UIAlertController

在iOS 8之前,可以在UIViewController被解除的同时从模式呈现的UIViewController中显示UIAlertView.我发现当用户需要提醒他们按下模态控制器上的"保存"按钮时发生的某些变化时,这一点特别有用.从iOS 8开始,如果UIAlertController在被取消时从模态呈现的视图控制器中显示,则UIAlertController也被解除.UIAlertController在用户可以阅读或自行解雇之前被解雇.我知道,一旦控制器被解除,我可以为模态控制器显示警报视图,但是这种情况会产生大量的额外工作,因为这个控制器在许多地方使用,并且必须向UIAlertController提供某些条件,要求在每种情况下将参数传递回控制器代表.有没有办法在控制器被解除的同时从模态呈现的控制器(或至少从控制器内的代码)显示UIAlertController,并让UIAlertController保持不变直到它被解除?

modal-dialog objective-c uiviewcontroller ios8 uialertcontroller

5
推荐指数
1
解决办法
2810
查看次数

循环遍历多个UIAlertController

在某些情况下,我的应用程序需要显示多个警报消息.在开始时收集错误消息,并且需要一次一个地向用户显示.当第一个被确认时,应该呈现下一个.问题是,他们都试图同时执行,显然.有同步的智能方法吗?这里有一些代码简单描述了我想要做的事情:

var errors : [NSError]!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let error1 = NSError(domain: "Test1", code: 1, userInfo: [NSLocalizedFailureReasonErrorKey : "Test1 reason."])

    let error2 = NSError(domain: "Test2", code: 2, userInfo: [NSLocalizedFailureReasonErrorKey : "Test2 reason."])

    let error3 = NSError(domain: "Test3", code: 2, userInfo: [NSLocalizedFailureReasonErrorKey : "Test3 reason."])

    errors = [error1, error2, error3]

}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    for error in errors {

        self.showAlert(error)

    }

}

func …
Run Code Online (Sandbox Code Playgroud)

synchronization swift uialertcontroller

5
推荐指数
1
解决办法
2325
查看次数

Swift属于左侧预期编号列表

我使用下面的代码来创建警报样式的规则列表 UIAlertController

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Left
let messageText = NSMutableAttributedString(
    string: "1. Do not bully or target other users.\n2. Do not post others' private information.\n3. Do not post useless or offensive content.\n4. Do not post others' copyrighted content.\n5. Downvote and Flag posts which violate these rules.\n6. If you violate these rules, your account may be suspended and/or your content removed.",
    attributes: [
        NSParagraphStyleAttributeName: paragraphStyle,
        NSFontAttributeName : UIFont(name: "Lato-Regular", size: 13.0)!,
        NSForegroundColorAttributeName : colorAccentWords
    ]
)
Run Code Online (Sandbox Code Playgroud)

它给了我警报视图,如下所示: 在此输入图像描述

我想要的是使编号列表保持预期,以便每行的溢出文本将保持对齐.我怎样才能做到这一点?

nsattributedstring swift uialertcontroller numbered-list

5
推荐指数
1
解决办法
1019
查看次数

UIAlertController无法在iOS 9中运行

我添加了显示登录和密码文本字段的UIAlertController代码,它适用于iOS 8但在iOS 9中不起作用.文本字段缩小,如下图所示 在此输入图像描述

我正在尝试的代码如下:

 - (void)toggleLoginLdap:(UIViewController *)currentVC
 {

 if ([UIAlertController class])
        {


            self.alertController= [UIAlertController
                                       alertControllerWithTitle:@"Title of Msg"
                                       message:@"Hello"
                                       preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * action){
                                                           NSString *userName = self.alertController.textFields[0].text;
                                                           NSString *password = self.alertController.textFields[1].text;



                                                       }];
            UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
                                                           handler:^(UIAlertAction * action) {


                                                               [self.alertController dismissViewControllerAnimated:YES completion:nil];

                                                           }];


            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                 textField.placeholder = @"Username/Email";
                 //textField.preservesSuperviewLayoutMargins = YES;
                textField.autoresizesSubviews = YES;
            }];
            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                textField.placeholder = @"Password";
                textField.secureTextEntry = YES;
            }];
            //alertController.view.autoresizesSubviews = YES;
            [self.alertController …
Run Code Online (Sandbox Code Playgroud)

objective-c uialertview uialertcontroller ios9 xcode7

5
推荐指数
1
解决办法
2754
查看次数

改变色调UIAlertController iOS9

我不确定是否有人遇到过这种行为,但iOS9正在使我的UIAlertController色调从主窗口继承.是否有任何特定的方式,如UIAppearance,可以帮助和解决问题.

[[UICollectionViewCell appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
Run Code Online (Sandbox Code Playgroud)

tint objective-c uialertcontroller ios9

5
推荐指数
1
解决办法
524
查看次数

如何将更多参数传递给UIAlertAction的处理程序?

有没有办法将数组"listINeed"传递给处理函数"handleConfirmPressed"?我能够通过将其添加为类变量来实现这一点,但这似乎非常hacky,现在我想为多个变量执行此操作,因此我需要更好的解决方案.

func someFunc(){
   //some stuff...
   let listINeed = [someObject]

   let alert = UIAlertController(title: "Are you sure?", message: alertMessage, preferredStyle: UIAlertControllerStyle.Alert)
   alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
   alert.addAction(UIAlertAction(title: "Confirm", style: .Destructive, handler: handleConfirmPressed))
   presentViewController(alert, animated: true, completion: nil)
}

func handleConfirmPressed(action: UIAlertAction){
  //need listINeed here
}
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller uialertaction

5
推荐指数
1
解决办法
4531
查看次数

防止键盘自动出现在UIAlertController中

UIAlertController在Swift中有一个(警报样式),一切正常.但是,UITextField我添加到它的是一个可选字段,用户无需输入文本.问题是当我显示时UIAlertController,键盘与默认选择的文本字段同时出现.除非用户点击,否则我不希望键盘出现UITextField.如何才能做到这一点?

    let popup = UIAlertController(title: "My title",
        message: "My message",
        preferredStyle: .Alert)
    popup.addTextFieldWithConfigurationHandler { (optionalTextField) -> Void in
        optionalTextField.placeholder = "This is optional"
    }
    let submitAction = UIAlertAction(title: "Submit", style: .Cancel) { (action) -> Void in
        let optionalTextField = popup.textFields![0]
        let text = optionalTextField.text
        print(text)
    }
    let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
    popup.addAction(cancelAction)
    popup.addAction(submitAction)
    self.presentViewController(popup, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

uitextfield uikeyboard ios swift uialertcontroller

5
推荐指数
1
解决办法
840
查看次数

即使出现警报也隐藏状态栏

我躲在我的状态栏上的特定viewController使用

override func prefersStatusBarHidden() -> Bool {
    return true
}
Run Code Online (Sandbox Code Playgroud)

直到我在屏幕上显示警报之前,它的工作都非常好。当出现警报时,状态栏再次出现,这是我不想要的。解除警报后,状态栏将再次隐藏。

statusbar ios swift uialertcontroller

5
推荐指数
1
解决办法
1440
查看次数

在Swift 3中的UIAlertController中自动换行

我正在swift 3中构建一个测验应用程序,利用UITableViewController列出问题,我想要使用的是一个警报视图,用于发布问题,并提供各种答案供您选择.我让它按照我想要的方式使用一个巨大的怪癖,那就是长答案得到一个更小的字体,并通过用省略号交换答案中间的文本来截断.

如何在AlertView操作中获得自动换行的答案,并保持相同大小的字体?请注意,在某个字符长度之后在答案中手动插入"\n"是不现实的,因为问题字典中有数百个问题.

在此输入图像描述

这是AlertView的代码:

func showQuestion(questionNum: Int) {

        let alertTitle = "Question \(questionNum + 1)"
        let qDict = test[questionNum] as! [String:String]
        let alertMessage = qDict["Question"]

        // create the alert
        let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)

        // add the actions (buttons)
        if qDict["Option-A"] != "" {
            alert.addAction(UIAlertAction(title: qDict["Option-A"], style: UIAlertActionStyle.default, handler: nil))
        }

        if qDict["Option-B"] != "" {
            alert.addAction(UIAlertAction(title: qDict["Option-B"], style: UIAlertActionStyle.default, handler: nil))
        }

        if qDict["Option-C"] != "" {
            alert.addAction(UIAlertAction(title: qDict["Option-C"], style: UIAlertActionStyle.default, handler: nil))
        }

        if …
Run Code Online (Sandbox Code Playgroud)

ios uialertcontroller swift3

5
推荐指数
1
解决办法
952
查看次数