将TextView添加到UIAlertView

时间:2013-03-05 07:10:27

标签: iphone uialertview

当我在alertview上添加textview时,scollview显示在文本的顶部和后面,如何克服这个问题。这是代码

问题已更新:

如果设置textView.editable = NO;它工作正常,但在我的情况下,我需要在textview中键入文本。

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

    [textView setText:@"lashdasjh asdasjdas asdlajsdl adsjajadsd aslj daj sdjasdjasjdlasjd as dlasj d"];

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Type Your Message" message:@"\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Send",nil];

    av.alertViewStyle = UIAlertViewStyleDefault;

    [av addSubview:textView];

    [av show];

enter image description here enter image description here

3 个答案:

答案 0 :(得分:4)

解决了我自己。删除邮件中的@"\n\n\n\n\n\n"并在标题中添加@"\n\n\n\n\n\n"

enter image description here

答案 1 :(得分:0)

这在IOS7上不再有效,但使用https://github.com/wimagguc/ios-custom-alertview可以帮助您完成相当好的工作

答案 2 :(得分:-1)

使用此代码替换您的代码,工作正常。

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

UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Type Your Message" message:@"\n\n\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Send",nil];

av.alertViewStyle = UIAlertViewStyleDefault;

[av addSubview:textView];

[av show];