UISearchbar的取消按钮的图像

use*_*388 10 iphone uibutton uiimage uisearchbar ios

可能重复:
在UISearchBar中设置取消按钮的样式

我正在尝试为搜索UISearchBarBackground栏设置图像,我可以使用搜索栏的子视图为搜索栏设置图像,但我无法为搜索栏的取消按钮设置图像.我获得UINavigationButton了按钮的搜索栏子视图,但我不知道如何设置图像UINavigationButton.谁能帮我?

先感谢您

Par*_*shi 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;
        }
    }
Run Code Online (Sandbox Code Playgroud)