【问题标题】:Programatic Creation and Config of UITabBarController - Setting a system Image for a tabUITabBarController 的编程创建和配置 - 为选项卡设置系统图像
【发布时间】:2011-01-14 16:14:15
【问题描述】:

以编程方式在应用程序中创建 tabBar 相当简单:

self.tabBarController = [[UITabBarController alloc] init]; 
[self.view addSubview:_tabBarController.view];

UIViewController * tab1 = [[UIViewController alloc] init];
tab1.title = "A";

UIViewController * tab2 = [[UIViewController alloc] init];
tab2.title = "B";

_tabBarController.viewControllers = [NSArray arrayWithObjects:patientSearch,todoList,nil];

[tab1 release];
[tab2 release];

您还可以轻松地将图像放入选项卡中:

tab1.tabBarItem.image = [UIImage imageNamed:@"myIcon.png"];

但是如何将这些选项卡的图像设置为系统图像之一?(例如搜索、收藏夹、书签等)在 IB 中,这是通过更改“标识符”来设置的,但是如何设置你能以编程方式做到这一点

【问题讨论】:

    标签: iphone objective-c cocoa-touch ipad ios


    【解决方案1】:
     UITabBarItem *aTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
    

    UITabBarItem docs

    UITabBarSystemItem 可以在标签栏上使用的系统项。

    typedef enum {
       UITabBarSystemItemMore,
       UITabBarSystemItemFavorites,
       UITabBarSystemItemFeatured,
       UITabBarSystemItemTopRated,
       UITabBarSystemItemRecents,
       UITabBarSystemItemContacts,
       UITabBarSystemItemHistory,
       UITabBarSystemItemBookmarks,
       UITabBarSystemItemSearch,
       UITabBarSystemItemDownloads,
       UITabBarSystemItemMostRecent,
       UITabBarSystemItemMostViewed,
    } UITabBarSystemItem;
    

    设置patientSearch.tabBarItem = aTabBarItem;

    【讨论】:

    • tag的用例是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多