ios 开发 navigationbar上私有属性的获取

来源:互联网 发布:微软程序员 编辑:程序博客网 时间:2024/05/22 15:13
for (UIView *subview1 in self.navigationController.navigationBar.subviews) {

// ZYLog(@”%@”,[subview1 class]);
if ([subview1 isKindOfClass:NSClassFromString(@”_UIBarBackground”)]) {
UIView subview = (UIView )subview1;
// [subview.subviews[1] removeFromSuperview];
// UIImageView imageView = (UIImageView )subview.subviews[0];
// self.navigationBarBackgroundView = imageView;
for (UIView *subview2 in subview.subviews) {
// [subview2 removeFromSuperview];
}
}
}

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 8, 245, 28)];searchBar.placeholder = @"精品推荐";searchBar.delegate = self;self.navigationItem.titleView = searchBar;[searchBar setBackgroundImage:[UIImage new]];[searchBar setTranslucent:YES];//修改搜索框背景searchBar.backgroundColor=[UIColor clearColor];for (UIView *subview1 in searchBar.subviews) { //UIView: 0x7fe6f5410fc0; frame = (0 0; 245 28)    for (UIView *subview2 in subview1.subviews) { //UISearchBarBackground: 0x7fd2b7e11a60; frame = (0 0; 245 28)--UISearchBarTextField

// ZYLog(@”%@”,subview2);
if ([subview2 isKindOfClass:NSClassFromString(@”UISearchBarTextField”)]) {
UITextField textfield = (UITextField )subview2;
self.searchBarTextField = textfield;
textfield.backgroundColor = [UIColor clearColor];
textfield.layer.borderColor = [UIColor lightGrayColor].CGColor;
textfield.layer.borderWidth = 1.0f;
textfield.layer.cornerRadius = 5.0f;
textfield.layer.masksToBounds = YES;
}
}
}

0 0
原创粉丝点击