http://blog.csdn.net/zhanglei5415/article/details/6369119
http://hi.baidu.com/bunsman/blog/item/effd0aeae83bd8cad439c93d.html
http://www.cnblogs.com/lovecode/articles/2310991.html
有效隐藏UITabBar:http://www.devdiv.com/home.php?mod=space&uid=11574&do=blog&id=2085
- (void) hideTabBar:(BOOL) hidden
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0];
for(UIView *view in self.tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, 320, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 320-49, view.frame.size.width, view.frame.size.height)];
}
}
else
{
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 320)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 320-49)];
}
}
}
[UIView commitAnimations];
}
// 移除UITabBarController上的UITabBar
for(UIView *view in self.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
view.hidden = YES;
break;
}
}
NSArray *array = [tabBarCtrl.view subviews];
UITabBar *tabBar = [array objectAtIndex:1];
UIImage *image = [UIImage imageNamed:@"background.png"];
tabBar.layer.contents = (id)image.CGImage;
@implementation UINavigationBar (CustomImage2)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
@implementation UIToolbar (CustomImage2)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
@implementation UITabBar (CustomImage2)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
UISearchBar的背景图片控制不是由自已控制的,而是由 UISearchBarBack来控制。
因此无法直接用上面的代码,需要手动把UISearchBar上面的两个View 删除了才行。
在你的ViewDidLoad 或者任何一个程序可以执行到的地方写下如下代码,
首先你得一个 UISearchbar。
// 删除UISearchbar上的 UISearchBarBackground
[[_searchBar.subviews objectAtIndex:0] setHidden:YES];
[[_searchBar.subviews objectAtIndex:0] removeFromSuperview];
for (UIView *subview in _searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
@implementation UISearchBar (CustomImage2)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"bar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end