I have a UIWebview contains a html "select" tag, which is shown as a on the screen.
When I click the dropdown, the UIWebview brings up a UIWebSelectSinglePicker View automatically, which is shown as .
我想更改选择器视图背景颜色和文本颜色。我怎样才能实现这个目标?
我尝试监听 UIKeyboardWillShowNotification 事件,但此时该视图尚未创建。
预先感谢您的任何帮助。
我自己设法解决了这个问题。
如果有人也想动态更改 UIPickerView,请看一下:
首先,在 UIKeyboardWillShowNotification 事件上添加一个侦听器。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_pickerViewWillBeShown:) name:UIKeyboardWillShowNotification object:nil];
其次,当通知触发时,延迟后调用更改背景颜色方法。
- (void)_pickerViewWillBeShown:(NSNotification*)aNotification {
[self performSelector:@selector(_resetPickerViewBackgroundAfterDelay) withObject:nil afterDelay:0];
}
第三,浏览 UIApplication 窗口并找到 pickerView。您可以更改 pickerView 的任何内容。
-(void)_resetPickerViewBackgroundAfterDelay
{
UIPickerView *pickerView = nil;
for (UIWindow *uiWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *uiView in [uiWindow subviews]) {
pickerView = [self _findPickerView:uiView];
}
}
if (pickerView){
[pickerView setBackgroundColor:UIColorFromRGB(0x00FF00)];
}
}
(UIPickerView *) _findPickerView:(UIView *)uiView {
if ([uiView isKindOfClass:[UIPickerView class]] ){
return (UIPickerView*) uiView;
}
if ([uiView subviews].count > 0) {
for (UIView *subview in [uiView subviews]){
UIPickerView* view = [self _findPickerView:subview];
if (view)
return view;
}
}
return nil;
}
希望它会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)