2012-07-13 56 views
2

我有UIAlertViewUITextView。 on ViewDidAppear我用[textView setText:]做了一個大文本,但是提示顯示一個空的textView,只有當我觸摸textView滾動時,文本纔會出現。UIAlertView中的UITextView大文本

我應該怎麼做才能讓文本出現在alert中的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]; 

}

+0

編輯您的問題與代碼.. – Tirth 2012-07-13 09:00:14

+0

請創建警報+ TextView中提供的代碼。 – Nitish 2012-07-13 09:00:52

+0

它是否立即顯示(不滾動)當文本短,說只有一個字符? – user1071136 2012-07-13 09:02:33

回答

5

這是因爲你已經初步確定消息@ 「\ n \ n \ n \ n \ n \ n \ n」UIAlertView。先設置UITextView,然後將UIAlertView的消息設置爲textView的文本。

+0

不,我將消息參數與「\ n \ n」一起使用,以便將UITextView放置在alertView中。該文本是在textView ... – 2012-07-13 09:33:29

+0

嗯,我錯了。你是對的!謝謝:))) – 2012-07-13 09:35:55

+0

很高興幫助。 :) – Nitish 2012-07-13 09:40:35

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的大小在警報視圖相匹配。

0

試試這個:

UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Terms of Service" 
        message:[NSString stringWithFormat:@"%@ \n\n\n",myTextView.text] 
        delegate:self 
        cancelButtonTitle:@"Disagree" 
        otherButtonTitles:@"Agree",nil 
        ];