【问题标题】:Change background image of searchbar更改搜索栏的背景图片
【发布时间】:2011-07-10 21:57:01
【问题描述】:

更改搜索栏的背景颜色很容易。但是,我不知道如何更改其背景图像。没有直接的方法。 我需要帮助............... 我很欣赏任何给定的想法...

【问题讨论】:

标签: iphone objective-c background uisearchbar searchbar


【解决方案1】:
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.png"]];
iview.frame = CGRectMake(0, 0, 320, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];

【讨论】:

    【解决方案2】:
    searchBar.backgroundImage = [UIImage imageNamed:@"searchBackground"];
    

    【讨论】:

      【解决方案3】:

      如果要使用图片作为搜索栏的背景,可以使用,

      searchBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"search_bg.png"]];
      

      【讨论】:

        猜你喜欢
        • 2014-06-06
        • 2015-01-16
        • 2013-11-01
        • 2018-07-31
        • 2016-02-18
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多