继承UISearchBar. 重载setShowCancelButton.[super xxx]; ...for (UIView *subview in self.subview) {if (subview isKindeOfClass:UIButton.class]) {cancelButton * = (UIButton*) subview;break;}