2

我有一个UIAlertViewwith UITextView。在ViewDidAppear[textView setText:]使用大文本时,但警报显示一个空的 textView,并且只有在我触摸 textView 进行滚动后,才会出现文本。

我应该怎么做才能使文本出现在警报的 textView 中,而不滚动它以“刷新”它?

谢谢!

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];



    av = [[UIAlertView alloc]initWithTitle:@"Terms of Service" message:@"\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"Disagree" otherButtonTitles:@"Agree",nil];


    UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(12, 50, 260, 142)];


    [myTextView setTextAlignment:UITextAlignmentCenter];
    [myTextView setEditable:NO];

    myTextView.layer.borderWidth = 2.0f;
    myTextView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
    myTextView.layer.cornerRadius = 13;
    myTextView.clipsToBounds = YES ;

    [myTextView setText:@"LONG LONG TEXT"];

    [av addSubview:myTextView];

    [myTextView release];

    [av setTag:1];


    [av show];

}

4

3 回答 3

5

这是因为您最初将 message 设置为@"\n\n\n\n\n\n\n" for UIAlertView。设置您的UITextView第一个,然后将UIAlertView' 消息设置为 textView 的文本。

于 2012-07-13T09:26:56.710 回答
0

在警报视图中添加 \n 字符代替消息。然后创建一个 UILabel 添加到警报视图。像这样

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@\n\n\n", @"Title"] message:@"\n" delegate:self cancelButtonTitle:NEVER_DISPLAY_BUTTON_TEXT otherButtonTitles:nil];

[alert addButtonWithTitle:@"Text"];
[alert addButtonWithTitle:@"Text"];
[alert addButtonWithTitle:@"Text"];
[alert addButtonWithTitle:@"Text"];
[alert show];
newTitle = [[UILabel alloc] initWithFrame:CGRectMake(10,-55,252,230)];
newTitle.numberOfLines = 0;
newTitle.font = [UIFont  systemFontOfSize:15];
newTitle.textAlignment = UITextAlignmentCenter;
newTitle.backgroundColor = [UIColor clearColor];
newTitle.textColor = [UIColor whiteColor];
newTitle.text = [NSString stringWithFormat:@"%@",self.message];
[alert addSubview:newTitle];

您可能需要调整 Uilable 的大小以匹配警报视图。

于 2013-02-20T14:03:03.140 回答
0

试试这个:

UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Terms of Service" 
                    message:[NSString stringWithFormat:@"%@ \n\n\n",myTextView.text] 
                    delegate:self 
                    cancelButtonTitle:@"Disagree" 
                    otherButtonTitles:@"Agree",nil
                  ];
于 2014-01-31T08:01:20.940 回答