2012-02-22 56 views
0

我在UITextView後面插入UIButton時遇到了問題。我可以製作按鈕,它的工作很好,但不管我做什麼,它總是在textView前面畫出來。在視圖背景中的UIButton

- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
self.backgroundButton = [[UIButton alloc] initWithFrame:self.view.frame]; 
[self.backgroundButton addTarget:textView action:@selector(resignFirstResponder) forControlEvents:UIControlEventTouchDown]; 
[self.view insertSubview:self.backgroundButton aboveSubview:textView]; 
[self.view bringSubviewToFront:textView]; 
} 

回答

0

試試這個:

- (void)textViewDidBeginEditing:(UITextView *)textView 
{ 
self.backgroundButton = [[[UIButton alloc] initWithFrame:self.view.frame] autorelease]; 
[self.backgroundButton addTarget:textView action:@selector(resignFirstResponder) forControlEvents:UIControlEventTouchDown]; 
[self.view insertSubview:self.backgroundButton belowSubview:textView]; 
} 
+0

還不行。 :(該按鈕繪製在textview上。如果添加 [self.backgroundButton setBackgroundColor:[UIColor blueColor]]; 您可以看到 – 2012-02-25 05:10:51