【问题标题】:UISearchbar custom in iOS 6 and 7iOS 6 和 7 中的 UISearchbar 自定义
【发布时间】:2014-01-31 13:26:20
【问题描述】:

我希望我的 UISearchbar 看起来像这样。

我试过这个:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Helvetica Neue" size:20]];

[self.seachBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"background"] forState:UIControlStateNormal];

[self.seachBar setImage:[UIImage imageNamed:@"SearchIcon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

[self.seachBar setBackgroundImage:[UIImage imageNamed:@"background"]];
[self.seachBar setText:@"Search"];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

请指导或任何教程。

谢谢

【问题讨论】:

  • 您是使用搜索栏显示控制器还是在导航栏中添加搜索栏
  • 嗨 iDev,我使用搜索栏显示控制器

标签: ios iphone custom-controls uisearchbar


【解决方案1】:

试试这个代码

 for (UIView *searchBarSubview in [searchBar subviews])
    {
        if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)])
        {

            [[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"background"]forState:UIControlStateNormal];
            [(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleNone];

            [[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"search"]];
            [[UISearchBar appearance] setTintColor:[UIColor clearColor]];
        }

    }

希望您的问题解决了...

【讨论】:

    【解决方案2】:

    参考下面的链接更有用,你不会浪费你的宝贵时间

    Right align magnifying glass icon in UISearchBar

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 2019-11-01
      • 2015-09-10
      相关资源
      最近更新 更多