zoukankan      html  css  js  c++  java
  • IOS6和IOS7 显示一样的SearchBar

     if (isIOS7) {
            mySearchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
            mySearchBar.autocorrectionType =  UITextAutocorrectionTypeNo;
            mySearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
            mySearchBar.keyboardType = UIKeyboardTypeDefault;
            mySearchBar.placeholder = @"全国地区(中文/拼音/区号/别名)                    ";
            mySearchBar.delegate =self;
            mySearchBar.tag = 100;
            mySearchBar.showsCancelButton =NO;//是否显示取消按钮
            [mySearchBar setBackgroundColor:MF_ColorFromRGB(229, 229, 229)];
            [[[[mySearchBar.subviews objectAtIndex:0] subviews] objectAtIndex:0] removeFromSuperview]; // 去掉搜索框背景
            [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:MF_ColorFromRGB(181, 181, 181)]; // 修改placeholder textColor
            [self.view addSubview:mySearchBar];
        }
        else
        {
            mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 2, 320, 40)];
            mySearchBar.delegate = self;
            mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
            mySearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
            mySearchBar.placeholder = @"全国地区(中文/拼音/区号/别名)";
            mySearchBar.keyboardType =  UIKeyboardTypeDefault;
            [mySearchBar setTranslucent:YES];
            mySearchBar.backgroundColor = MF_ColorFromRGB(229, 229, 229);
            [[mySearchBar.subviews objectAtIndex:0]removeFromSuperview];  // 去掉搜索框背景
            [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:MF_ColorFromRGB(181, 181, 181)]; // 修改placeholder textColor
            [self.view addSubview:mySearchBar];
            
            // 替换UITextField背景图
            UITextField* searchField = nil;
            for (UIView* subview in mySearchBar.subviews) {
                if ([subview isKindOfClass:[UITextField class]])
                {
                    searchField = (UITextField*)subview;
                    break;
                }
            }
            searchField.background = [MF_PngWithSkin(DEFAULTS_SKIN, @"search_Bar_bgImg.png") stretchableImageWithLeftCapWidth:30 topCapHeight:30];
        }
  • 相关阅读:
    UI是一个状态机
    WPF : Binding的3个属性: Source, RelativeSource, ElementName
    业务驱动设计
    WPF : 对Collection要注意重用子控件
    WPF : UserControl的Initialized事件不会触发
    mvc3上传图片
    MVC3.0自定义视图引擎(切换皮肤)
    ASP.NET MVC 多语言解决方案
    键盘键位表
    Silverlight之IsolatedStorageSettings对象
  • 原文地址:https://www.cnblogs.com/joesen/p/3783226.html
Copyright © 2011-2022 走看看