如何将UISearchBar上"Cancel"按钮改为”取消“
1个回答
展开全部
///#begin
//
//功能描述:修改SearchBar的Cancel Button 的Title
// 注意点:
// 使用iOS8 SDK ,本次 UISearchBar适用于iOS7(+)版本,如果想要适配iOS6,则需要对应适配iOS6.
// 例如:
// iOS7+ : for(id cc in [searchBar.subviews[0] subviews]){}
// iOS7- : for(id cc in [searchBar subviews]){}
//
///#end
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
for(id cc in [searchBar.subviews[0] subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:[AppLanguageProcess getLanguageWithKey:@"TEXT_CANCEL"] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}
//
//功能描述:修改SearchBar的Cancel Button 的Title
// 注意点:
// 使用iOS8 SDK ,本次 UISearchBar适用于iOS7(+)版本,如果想要适配iOS6,则需要对应适配iOS6.
// 例如:
// iOS7+ : for(id cc in [searchBar.subviews[0] subviews]){}
// iOS7- : for(id cc in [searchBar subviews]){}
//
///#end
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
for(id cc in [searchBar.subviews[0] subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:[AppLanguageProcess getLanguageWithKey:@"TEXT_CANCEL"] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询