UIToolbar 的多个自定义背景
为了在 tableView 顶部创建绝对底部页脚,我发现使用 UIToolbar 并为其添加自定义视图效果很好。
我的问题是,我已经将其用作网络视图的工具栏,并且这里使用了我现在不需要的另一个背景图像。
通过替换 UIToolbar+addition.m 中的 drawRect 函数,我有一个全局工具栏,可以在我的 web 视图中正常工作。
我如何扩展它以便我可以选择在不同地方使用哪个版本(背景)?
我的 UIToolbar+addition.m:
#import "UINavigationBar+addition.h"
@implementation UIToolbar (Addition)
- (void) drawRect:(CGRect)rect {
UIImage *barImage = [UIImage imageNamed:@"toolbar-bg.png"];
[barImage drawInRect:rect];
}
@end
In order to create an absolute bottomed footer on top of a tableView I found that using UIToolbar for this and adding custom views for it worked fine.
My problem is that I already use this as a toolbar for a webview, and here with another background image than I need now.
By replacing the drawRect function in UIToolbar+addition.m I have a global toolbar for this that works fine in my webviews.
How can I expand this so that I can select which version(background) to use the different places?
My UIToolbar+addition.m:
#import "UINavigationBar+addition.h"
@implementation UIToolbar (Addition)
- (void) drawRect:(CGRect)rect {
UIImage *barImage = [UIImage imageNamed:@"toolbar-bg.png"];
[barImage drawInRect:rect];
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试为每个“版本”创建单独的 .h 和 .m 文件,并将适当的 .h 导入到您希望它影响的类文件中。
Try creating separate .h and .m files for each "version", and import the appropriate .h into the class file you'd like it to affect.
为什么不直接将 barImage 属性添加到您的扩展中呢?
然后,在你的实现中(我这样做是假设你没有使用 ARC。如果你使用了,显然删除保留/释放的东西):
现在,你所要做的就是在实例化你的 UIToobar 后设置 barImage 属性。例如:
并且,如果您想在屏幕上显示后更改它,只需将 barImage 属性设置为新的 UIImage 即可。
看起来这个问题已经发布一年了,但希望这可以对某人有所帮助。
Why not just add a barImage property to your extension?
Then, in your implementation (I'm doing this assuming you're not using ARC. If you are, obviously remove the retain/release stuff):
Now, all you have to do is set the barImage property after instantiating your UIToobar. e.g.:
And, if you want to change it after it's already onscreen, you can do so by just setting the barImage property to a new UIImage.
Looks like it's been a year since this question was posted, but hopefully this might help someone.