如何通过html选择标签创建UIPickerView的对象引用 [英] How to get object referece of UIPickerView when it create through html select tag

查看:139
本文介绍了如何通过html选择标签创建UIPickerView的对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWebview包含一个htmlselect标记,它显示为屏幕。



当我点击下拉菜单时,UIWebview会自动弹出一个UIWebSelectSinglePicker视图,显示为。



我想更改选取器视图的背景颜色和文本颜色。我怎样才能达到这个目标?



我尝试在UIKeyboardWillShowNotification事件上进行侦听,但是在那个时候,这个视图还没有创建。



感谢您的帮助。



如果有人也想立即更改UIPickView,请看一看:

首先,添加UIKeyboardWillShowNotification事件监听器。

pre $ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_pickerViewWillBeShown :) name:UIKeyboardWillShowNotification object :零];

第二,当通知被触发时,延迟后调用背景颜色方法。 < - 这是非常重要的,如果调用方法没有延迟,pickview在那时不存在。

   - ( 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]]){$ b $ {

}

b返回(UIPickerView *)uiView; $ {
}
if([uiView subviews] .count> 0){
for(UIView * subview in [uiView subviews]){
UIPickerView * view = [self _findPickerView:子视图]。
if(view)
return view;
}
}
return nil;
}

希望这会有所帮助。

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 .

I want to change the picker view background color and text color. How can I achieve this goal?

I tried to listen on UIKeyboardWillShowNotification event, but at that moment, this view has not been created.

Thanks in advance for any helps.

解决方案

I managed to resolve the issue myself.

If someone also want to change the UIPickView on the fly, please take a look:

First, add a listener on UIKeyboardWillShowNotification event.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_pickerViewWillBeShown:) name:UIKeyboardWillShowNotification object:nil];

Second, when notification fired, call change background color method after delay. <-- This is very important, if call method without delay, the pickview does not exist at that moment.

- (void)_pickerViewWillBeShown:(NSNotification*)aNotification {
   [self performSelector:@selector(_resetPickerViewBackgroundAfterDelay) withObject:nil   afterDelay:0];
}

Third, go through the UIApplication windows and find out pickerView. And you can change what ever you want for 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;
}

Hope it will help.

这篇关于如何通过html选择标签创建UIPickerView的对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆