如何使用更高版本的 iOS 4.2 覆盖 UIToolbar 方法
此代码适用于 iPad Simulator 4.2,但不适用于更高版本的 iOS4.3 或更高版本。我无法覆盖 UIToolbar 类方法。
@implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect
{
UIImage *image = [[UIImage imageNamed:@"ToolBar.png"] retain];
[image drawInRect:rect];
[image release];
}
//return 'best' size to fit given size. does not actually resize view. Default is return existing view size
- (CGSize)sizeThatFits:(CGSize)size {
CGSize result = [super sizeThatFits:size];
result.height = 80;
return result;
};
替代解决方案是什么?请指导我。 在更高版本中..- (void)drawRect:(CGRect)rect 永远不会被调用。
使用 iPad Simulator 4.2 代码运行可以正常运行,但使用 iPad Simulator 4.3 时,drawRect 从未被调用过。
下面是工具栏的屏幕截图:
This code works fine with iPad Simulator 4.2, but not with later version of iOS4.3 or after that.I am not able to Override the UIToolbar class methods.
@implementation UIToolbar (CustomImage)
- (void)drawRect:(CGRect)rect
{
UIImage *image = [[UIImage imageNamed:@"ToolBar.png"] retain];
[image drawInRect:rect];
[image release];
}
//return 'best' size to fit given size. does not actually resize view. Default is return existing view size
- (CGSize)sizeThatFits:(CGSize)size {
CGSize result = [super sizeThatFits:size];
result.height = 80;
return result;
};
What would be the alternate solution for this ?Please guide me.
In later version ..- (void)drawRect:(CGRect)rect is never called .
Running with iPad Simulator 4.2 code works fine but with iPad Simulator 4.3 drawRect in never called.
Below is the Screenshot of Toolbar:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事怎么办?
What about something like this?
如果要将其实现为类别,则需要根据 iOS5 更改日志对 UIToolBar 进行子类化
you are implementing it as a category, you need to subclass UIToolBar based on the iOS5 change log