![](/img/trans.png)
[英]Is it possible to set the alpha property of a UITableViewCell accessoryView?
[英]Set alpha transparency on accessoryView
我試圖將UIView作為附件視圖添加到UITextField,但是似乎不尊重alpha屬性。
這是我當前的代碼。
self.keyboardAccView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
[self.keyboardAccView setBackgroundColor:[UIColor lightGrayColor]];
[self.keyboardAccView setOpaque:NO];
[self.keyboardAccView setAlpha:0.0];
UITapGestureRecognizer *hideKeyboardTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
[self.keyboardAccView addGestureRecognizer:hideKeyboardTap];
[hideKeyboardTap release], hideKeyboardTap=nil;
alpha值似乎無關緊要。 無論我將其設置為什么,accessoryView始終設置為不透明。
我要完成的工作是在鍵盤上方顯示一個透明視圖,只要用戶從鍵盤上輕按一下,它便會關閉鍵盤。 如果有一種更好/合適的方法來使我完全不知所措,那么我也會全神貫注。
我知道我可以只使用[UIColor clearColor]
作為backgroundColor,但我更想知道為什么不采用alpha設置,以防萬一我確實確實想要一個半透明的AccessoriesView
是的-有更好的方法! :)
我個人是這樣做的-我更改了ViewController.xib類(將UIView更改為UIControl),然后創建了一個簡單的IBAction,只要輕按了UIControl,它就會辭職第一響應者。
該方法應如下所示:
- (IBAction)hideKeyboard {
[textField resignFirstResponder];
}
而已 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.