Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

objective c - 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 





 " message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"I Agree",nil];



[customAlert addSubview:tosTextView];

[customAlert show];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...