【问题标题】:UITabBarItem finishedImageSelected placed offsetting the tab barUITabBarItem finishedImageSelected 放置偏移标签栏
【发布时间】:2012-01-26 15:33:25
【问题描述】:

我正在尝试自定义 UITabBarItem,但图像的位置有问题。

图片大小为 81px x 49px,与 UITabBar 高度相同。这就是我设置图像的方式:

    // AppDelegate
    BlocosController *blocos = [[[BlocosController alloc] initWithManagedObjectContext:moc] autorelease];
    UINavigationController *navBlocos = [[[UINavigationController alloc] initWithRootViewController:blocos] autorelease];
    tabBarController = [[UITabBarController alloc] initWithManagedObjectContext:moc];
    tabBarController.viewControllers = [NSArray arrayWithObjects: navData, navBlocos, navBairro, navAtualizar, nil];

// ...

// BlocosController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:TITLE image:nil tag:10] autorelease];
        [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_blocos_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_blocos_unselected"]];
    }
    return self;
}

我在谷歌上搜索并找到了this tutorial,代码使用与我使用的相同的 API 并且按预期工作。 本文中的代码行为与我的一样,但是因为它们的背景颜色相同,所以会产生一种正确放置的错觉。

为什么finishedImageSelected 和unselected 和tab 标签不对齐?如何解决?

【问题讨论】:

    标签: objective-c cocoa-touch ios5


    【解决方案1】:

    我找到了完成此任务的正确方法并发了一个帖子:felipecypriano.com/2012/02/27/…

    基本上问题是finishedImage是图标而不是图标和背景,可以通过调整imageInset属性与背景一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多