本文介绍了如何制作多行,左对齐的UIAlertView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣制作一个左对齐的UIAlertView,其中有几行像公告列表一样,如下所示:

I am interested in making a left-aligned UIAlertView with several lines like a bulletin list that would look like the following:


  • line 1

  • 第2行

  • 第3行

这是我到目前为止所拥有的:

Here's what I have so far:

alert = [[UIAlertView alloc] initWithTitle: @"How to use buttons"
                                   message: @"line 1. line 2, line 3 "
                                  delegate: nil
                         cancelButtonTitle: @"OK"
                         otherButtonTitles: nil];

我还想将警报视图的颜色更改为红色。

I also want to change the color of the alert view to red.

推荐答案

项目符号由unicode代码0x2022表示。我用它来使用\ n来表示新行:

Bullets are represented by the unicode code 0x2022. I got it to work like this using "\n" for new lines:

UIAlertView *alert = [[UIAlertView alloc]
            initWithTitle: @"How to use buttons"
            message: [NSString stringWithFormat: @"%C line 1.\n %C line 2,\n %C line 3", (unichar) 0x2022, (unichar) 0x2022, (unichar) 0x2022];
            delegate: nil
            cancelButtonTitle:@"OK"
            otherButtonTitles:nil];

这应适用于子弹。

对于左对齐,请执行以下操作:

For the left alignment, do this:

NSArray *subViewArray = alertView.subviews;
for(int x = 0; x < [subViewArray count]; x++){

    //If the current subview is a UILabel...
    if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]]) {
        UILabel *label = [subViewArray objectAtIndex:x];
        label.textAlignment = NSTextAlignmentLeft;
    }
}

总结如下:


  • \ n用于显示新行

  • [ NSString stringWithFormat:@%C Line n,(unichar)0x2022]; 表示项目符号

  • 对于 alignment ,遍历警报视图的子视图,并确定哪些子视图是 UILabel 的子类。然后使用 label.textAlignment = NSTextAlignmentLeft 将标签的文本对齐方式更改为左对齐。

  • 执行 all 这个,然后你可以打电话给 [提示秀];

  • "\n" for displaying new lines.
  • [NSString stringWithFormat:@"%C Line n", (unichar) 0x2022]; for the bullets.
  • For the alignment, iterate through the subviews of the alert view and identify which subviews are subclasses of UILabel. Then change the text alignment of the labels to left alignment using label.textAlignment = NSTextAlignmentLeft.
  • After you do all this, then you can call [alert show];.

这篇关于如何制作多行,左对齐的UIAlertView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 14:42
查看更多