【发布时间】:2012-02-20 15:52:54
【问题描述】:
从文档中,我看到了 backBarButtonItem:
当此属性为 nil 时,导航项使用其中的值 title (page 10) 属性来创建适当的后退按钮。如果你 想要为后退按钮指定自定义图像或标题,您可以 将自定义栏按钮项(带有您的自定义标题或图像)分配给 而不是这个属性。配置条形按钮项目时,不要 为其分配自定义视图;导航项忽略自定义视图 无论如何都在后栏按钮中。
我不知道 leftBarButtonItem 是否也一样?基本上我有这个代码:
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIImage *homeImage = [UIImage imageNamed:@"icon_house.png"];
[homeButton setImage:homeImage forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *homeBBI = [[UIBarButtonItem alloc] initWithCustomView:homeButton];
在 iOS 5 之前,我把它放在 UIToolBar 中,它显示得很好。现在我想把它作为leftBarButtonItem,放在UINavigationController 的backButton 的右边。当我设置它时,它根本不显示。没有图像。但是,当我创建这样的按钮时:
UIBarButtonItem *hButton = [[UIBarButtonItem alloc] initWithTitle:@"home" style:UIBarButtonItemStylePlain target:self action:@selector(homePressed:)];
并将其设置为leftBarButtonItem,它就会显示出来。我不知道如何获得没有边框的主页按钮的自定义图标。当我使用时:
UIBarButtonItem *hButton2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_house.png"] style:UIBarButtonItemStylePlain target:self action:@selector(homePressed:)];
我的 house_icon 周围有一个我不想要的边框。谢谢。
【问题讨论】:
标签: iphone uinavigationcontroller uinavigationitem