开发者

Automatically highlight UITabBar Button

I'm using this method http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited to create a custom UITabBar and loading a particular view when a certain TabBarItem is clicked.

The problem is that init开发者_开发知识库ially the first view is loaded, but the first tab bar item is not highlighted. Is there a way to force the highlight? I'm not using the tabbarcontroller so I can't use its methods.


If you make an instance variable: UITabBar *tabBar; a property:

@property (nonatomic, assign) IBOutlet UITabBar *tabBar;

and connect this property to the UITabBar in Interface Builder, you can use:

for(UITabBarItem *tab in tabBar.items) {
    if ([tab.title isEqualToString: @"My Tab Title"]) {
        tabBar.selectedItem = tab;
        }
    }

This works if all tabs have a unique title, which is normally the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜