iOS UISearchBar 获取 cancelButton,UItextField

获取CancelButton,代码以下:orm

for (UIView *view in [[_searchBar.subviews lastObject] subviews]) {it

        if ([view isKindOfClass:[UIButton class]]) {ast

            UIButton *cancelBtn = (UIButton *)view;            class

            NSAttributedString *str2 = [[NSAttributedString alloc] initWithString:@"取消" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:COLORWITH_RGB(82, 158, 204)}];            file

            [cancelBtn setAttributedTitle:str2 forState:UIControlStateNormal];view

        }vi

    }search

 

获取UItextfiled,代码以下:arc

for (UIView *view in [[_searchBar.subviews lastObject] subviews]){

        if ([view isKindOfClass:[UITextField class]]) {

            UITextField *textFiled = (UITextField*)view;

        }

    }

虽然获取到了试图,但有一些属性无法设置,只能对一些进行处理

相关文章
相关标签/搜索