【问题标题】:UIActionSheet/UIAlertController multiline textUIActionSheet/UIAlertController 多行文本
【发布时间】:2015-10-19 13:25:40
【问题描述】:

这是我要显示UIActionSheet 的代码。

actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"updateresponseforrecurring", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:
                   NSLocalizedString(@"updateresponseonlyforthis", nil),
                   NSLocalizedString(@"updateresponseforallactivities", nil),
                   nil];
    actionSheet.tag = 2;
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow];  

这就是我用这个得到的:

显然,第二个选项更长,因此尺寸会变小以适应宽度。
但是我希望所有选项都使用相同的字体大小,这让我有了多行。还尝试使用UIAlertController,但无法设置多行文本。 如何做到这一点?

【问题讨论】:

    标签: ios uiactionsheet uialertcontroller


    【解决方案1】:

    这似乎适用于 iOS 10 和 Swift 3.1:

    UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 2
    

    【讨论】:

    • 您也可以将 numberOfLines 设置为 0。这样可以根据需要允许尽可能多的行。
    【解决方案2】:

    这对于标准 UIAlertControllerUIAlertView 是不可能的。 我建议你缩短它。你为什么不发出警报并输入这样的内容:

    您想仅更新此实例的响应还是所有 本系列活动。

    答案如下:

    • 仅此实例
    • 所有活动

    【讨论】:

    • 如果我的回答确实帮助您解决了您的问题,请将其选为已接受的答案。谢谢!
    【解决方案3】:

    在 iOS 10 中:

    如果你想将它应用到所有 UIAlertController,你可以使用这几行代码:

    [[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setNumberOfLines:2];
    [[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setFont:[UIFont systemFontOfSize:9.0]];
    

    把它放在 AppDelegate 的 didFinishLaunchingWithOptions 方法中。

    【讨论】:

      【解决方案4】:

      试试这个

      let alert = UIAlertController(title: title,
                                    message: "you message go here",
                                    preferredStyle: 
      UIAlertControllerStyle.alert)
      
      let cancelAction = UIAlertAction(title: "Cancel",
                                       style: .cancel, handler: nil)
      
      alert.addAction(cancelAction)
      self.present(alert, animated: true, completion: nil)
      
      UILabel.appearance(whenContainedInInstancesOf: 
      [UIAlertController.self]).numberOfLines = 0
      
      UILabel.appearance(whenContainedInInstancesOf: 
      [UIAlertController.self]).lineBreakMode = .byWordWrapping
      

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。
      猜你喜欢
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多