Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Insert the UITextView into UIAlertview in iOS

Also, I would like this UITextView with the text file in XXX.txt.It works fine in iOS6, but content does not appear on the UIAlertview in iOS7. my code is given as below:-

UITextView *tosTextView = [[UITextView alloc]initWithFrame:CGRectMake(12, 48, 260, 140)];

NSString *path = [[NSBundle mainBundle] pathForResource:@"TJTermsof Service"
                                                 ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:path
                                              encoding:NSUTF8StringEncoding
                                                 error:NULL];
[tosTextView setText:content];

tosTextView.textColor=[UIColor blackColor];
tosTextView.font = [UIFont fontWithName:@"LuzSans-Book" size:17];
tosTextView.editable = NO;
customAlert = [[UIAlertView alloc]initWithTitle:@" TOS \n\n\n\n\n\n " message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"I Agree",nil];



[customAlert addSubview:tosTextView];

[customAlert show];
like image 750
Anbu.Karthik Avatar asked Dec 23 '13 05:12

Anbu.Karthik


4 Answers

This should work. Give it a shot. But it's a hack and might not be appreciated by Apple.

UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:title
                                                    message:@""
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Done", nil];
UITextView *textView = [UITextView new];
if (SYSTEM_VERSION_LESS_THAN(@"7.0"))//For Backward compatibility 
{
    [testAlert addSubview: textView];
}
else
{
    [testAlert setValue: textView forKey:@"accessoryView"];
}
[testAlert show];
like image 196
Koushik Ravikumar Avatar answered Nov 16 '22 08:11

Koushik Ravikumar


the following link has resolved my problem, the link is https://github.com/wimagguc/ios-custom-alertview

the following content has resolved

  1. textview
  2. tableview
  3. ImageView
  4. UIWebView

both functionalities are worked as fine for me

like image 33
Anbu.Karthik Avatar answered Nov 16 '22 09:11

Anbu.Karthik


You cannot modify the alert view view hierarchy in iOS7.

You need to either roll your own implementation of an alert view, or use an open source implementation, such as SDCAlertView.

like image 32
Léo Natan Avatar answered Nov 16 '22 08:11

Léo Natan


I have tested this myself.

By default UIAlertview content is a textview. How large you are giving the content UIAlertview will definetly present it in a textview.

I think you have given the text in Alertview title. You should have given it in the message.

enter image description here

like image 26
ipraba Avatar answered Nov 16 '22 10:11

ipraba