今天要做一个搜索功能,用到UISearchBar 无奈背景太丑,就自定义了一个,首先用View私有方法打印一下searchBar的层次,
具体修改代码如下
for (UIView *view in _topSerachBar.subviews) { if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) { [[view.subviews objectAtIndex:0] removeFromSuperview]; [[view.subviews objectAtIndex:0] setBackgroundColor:[UIColor redColor]]; [[view.subviews objectAtIndex:1] setTitle:@"自定义"]; break; } } }
时间: 2024-10-16 00:08:22