【问题标题】:UIAlertView message with bold text带有粗体文本的 UIAlertView 消息
【发布时间】:2012-03-19 20:26:36
【问题描述】:

我正在尝试获取“消息”中的一些文本,以便我的 UIAlertView 显示为粗体。像这样:

UIAlertView 消息: 标题 一些文字,新标题 一些文字

我尝试过使用基本的 html 格式(因为“/n”适用于换行),但这对我不起作用。有没有一种简单的方法可以使某些文本变粗?

当然,如果没有,我总是可以为警报视图编写自定义实现,但如果有更简单的方法,如果有人能告诉我,我会很高兴:)

【问题讨论】:

  • 恐怕获得此功能的唯一方法是实现您自己的警报视图,如果您需要帮助,请告诉我们。
  • 您必须添加一些子视图或制作自己的警报视图。 This link 可能会有所帮助

标签: iphone uialertview


【解决方案1】:

响应耐嚼的回答,可以将文本字段添加到 iOS7 中的 UIAlertView,只需替换

[alertView addSubview:txtField];

[alertView setValue:txtField forKeyPath:@"accessoryView"];

【讨论】:

    【解决方案2】:

    这是您要查找的代码,没有创建自定义警报

    不适用于 iOS7

      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
        UILabel *txtField = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 25.0, 260.0, 95.0)];
        [txtField setFont:[UIFont fontWithName:@"Helvetica-Bold" size:(18.0)]];
        txtField.numberOfLines = 3;
        txtField.textColor = [UIColor redColor];
        txtField.text = @"Look at me, I am a Red and Bold Label.";
        txtField.backgroundColor = [UIColor clearColor];
        [alertView addSubview:txtField];
        [alertView show];
    

    【讨论】:

      【解决方案3】:

      如果您的应用程序在 iOS 6 或更低版本下运行,这一切都很好,但不幸的是,您无法在 iOS7 中将子视图添加到警报视图中。 因此,如果您只需要以粗体显示消息并且您对创建自定义视图不感兴趣,则可以在消息留空时简单地将文本添加到标题。

      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your message"
                                                          message:@""
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
      [alertView show];
      

      【讨论】:

        【解决方案4】:
        UILabel *alertMessage =  [alert.subviews objectAtIndex:1]; 
        alertMessage.textColor = [UIColor redColor]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-20
          • 1970-01-01
          • 2021-07-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-09-07
          • 2014-09-04
          相关资源
          最近更新 更多