可以创建带有自定义图像(按下/未按下)的 UITabBarController 吗?
我想为我的申请添加一点天赋,虽然我取得了一些成功,但我还没有找到一种方法来真正做我想做的事情。 我会尝试子类化 UITabViewController,但我认为我什至不知道从哪里开始或者这是否是正确的方法。
基本上,我想要做的是为每个选项卡栏按钮提供自定义图像。 我有压制图像和非压制图像。 我希望显示按下的图像,而不是使用当前图标上生成的突出显示。 我能够做的是使用自定义的drawRect方法创建一个UITabBar的类别,该方法基本上绘制了我所有的自定义选项卡栏图标。 然后,我初始化相同数量的 UITabBarItems,无需指定任何类型的图像或标题,然后将其添加到项目数组中。 这让我可以拥有自己的图标,然后将突出显示的内容覆盖在它们上。
我想这没问题,但我真的很想看看按下的按钮。
这是我用于绘制选项卡栏的代码:
@implementation UITabBar (CustomImage)
-(void)drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:@"TabBar.png"];
[image drawInRect:CGRectMake(0,0,320,50)];
}
@end
然后我像这样初始化选项卡栏项目:
UITabBarItem *homeTabBarItem = [[UITabBarItem alloc] init];
如果有人知道我将如何做到这一点,那将不胜感激。 请记住,我对 Objective-C 还比较陌生,所以我对此时如何正确地对任何内容进行子类化有些困惑。
我正在寻找的功能类似于 RougeSheep 能够通过 Postage 完成的功能: http://postage.roguesheep .com/ 他们做得非常出色,这正是我想要效仿的。
I want to add a little flair to my application and while I have been somewhat successful, I haven't figured out a way to truly do what I want to do. I would try to subclass UITabViewController, but I don't think I would even know where to start or if that is the right approach.
Basically, what I want to do is have custom images for each tab bar button. I have both pressed and non-pressed images. Instead of using the highlight that is generated over the current icon, I want the pressed image to be shown. What I've been able to do is create a Category of the UITabBar with a custom drawRect method that basically draws all of my custom tab bar icons. I then initialize the same amount of UITabBarItems w/out specifying an image or title of any kind which I then add to the array of items. This lets me have my icons and then just overlays the highlight on them.
This is ok I guess, but I would really like to have the pressed button look.
Here is the code I use for drawing the tab bar:
@implementation UITabBar (CustomImage)
-(void)drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:@"TabBar.png"];
[image drawInRect:CGRectMake(0,0,320,50)];
}
@end
And then I initialize the tab bar items like this:
UITabBarItem *homeTabBarItem = [[UITabBarItem alloc] init];
If anyone knows how I would do this, that would be greatly appreciated. Please keep in mind that I'm still relatively new to Objective-C, so I'm somewhat confused as to how I would correctly subclass anything at this point.
The functionality I'm looking for would be similar to what RougeSheep was able to accomplish with Postage: http://postage.roguesheep.com/ They did an awesome job, and this is kind of what I'd like to emulate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论