UINavagationBar,UISearchBar,UITo…
2013-12-20 12:59
323 查看
这里运用了
object-c里面的一个类别,大体意思就是在不知道苹果封装起来的API内容的情况下,在外部程序中覆盖其原来的函数。大体这个意思吧。
程序代码: 在程序的任何一个 .m文件 后面加上下面代码即可 记住 要在
@end 的后面加上;
@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
上面这三个的用法都是一样的,关键是SearchBar
SearchBar的背景图片控制不是由SearchBar 本身 而是由
UISearchBarBack 来控制的,因此无法直接用上面的代码,需要手动把SearchBar上面的两个View
删除了才行。
且看删除代码:
在你的ViewDidLoad 或者任何一个程序可以执行到的地方 写下如下代码,不过首先你得nib 一个 UISearchbar
才行的
[[_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
OK了。
object-c里面的一个类别,大体意思就是在不知道苹果封装起来的API内容的情况下,在外部程序中覆盖其原来的函数。大体这个意思吧。
程序代码: 在程序的任何一个 .m文件 后面加上下面代码即可 记住 要在
@end 的后面加上;
@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
上面这三个的用法都是一样的,关键是SearchBar
SearchBar的背景图片控制不是由SearchBar 本身 而是由
UISearchBarBack 来控制的,因此无法直接用上面的代码,需要手动把SearchBar上面的两个View
删除了才行。
且看删除代码:
在你的ViewDidLoad 或者任何一个程序可以执行到的地方 写下如下代码,不过首先你得nib 一个 UISearchbar
才行的
[[_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
OK了。
相关文章推荐
- UINavagationBar,UISearchBar,UITo…
- UINavagationBar,UISearchBar,UIToolBar,UITabBar 自定义 Background Image
- UINavagationBar,UISearchBar,UIToolBar,UITabBar 自定义 Background Image
- UINavagationBar,UISearchBar,UIToolBar,UITabBar 自定义 Background Image
- UINavagationBar,UISearchBar,UIToolBar,UITabBar 自定义 Background Image
- UITableView + UISearchBar 实现搜索功能
- UISearchBar 取消按钮中文设置
- UISearchBar和导航栏按钮
- 更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底
- UISearchBar 搜索框
- iOS中UISearchBar(搜索框)使用总结
- iOS UISearchBar学习笔记
- UISearchBar改变输入框的背景颜色
- iOS开发-搜索栏UISearchBar和UISearchController
- UISearchBar背景色及边框修改
- UISearchBar与UITableView的联合使…
- UISearchBar使用总结
- ios中UISearchBar的placeHolder左对齐
- UISearchController,SearchBar的教程-Swift
- UISearchBar使用及修改样式