UISearchbar的取消按钮的图像

时间:2012-12-24 09:52:32

标签: iphone ios uibutton uiimage uisearchbar

  

可能重复:
  Styling the cancel button in a UISearchBar

我正在尝试为搜索栏设置图片,我可以使用搜索栏的子视图UISearchBarBackground为搜索栏设置图片,但我无法为搜索栏的取消按钮设置图片。我获取了按钮的搜索栏子视图UINavigationButton,但我不知道如何在UINavigationButton上设置图像。任何人都可以帮助我吗?

提前谢谢

1 个答案:

答案 0 :(得分:10)

试试这段代码......

    for (UIView *searchbuttons in searchBar.subviews)
    {
        if ([searchbuttons isKindOfClass:[UIButton class]])
        {
            UIButton *cancelButton = (UIButton*)searchbuttons;
            cancelButton.enabled = YES;
            [cancelButton setBackgroundImage:[UIImage imageNamed:@"yourImageName"] forState:UIControlStateNormal];
            break;
        }
    }