如何在iOS中的UIAlertview中插入UITextView

Anb*_*hik 10 objective-c uialertview ios swift

此外,我希望这个UITextView与XXX.txt中的文本文件.它在i​​OS6中工作正常,但内容不会出现在iOS7的UIAlertview上.我的代码如下: -

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];
Run Code Online (Sandbox Code Playgroud)

Kou*_*mar 6

这应该工作.试一试.但它是一个黑客,可能不会受到苹果的赞赏.

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];
Run Code Online (Sandbox Code Playgroud)


Anb*_*hik 4

以下链接解决了我的问题,链接是https://github.com/wimagguc/ios-custom-alertview

以下内容已解决

  1. 文本视图
  2. 表格视图
  3. 图像视图
  4. UIWeb视图

这两个功能对我来说都很好用