OGeek|极客世界-中国程序员成长平台

标题: iphone - 使用系统图标或图像图标的自定义导航栏按钮 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:45
标题: iphone - 使用系统图标或图像图标的自定义导航栏按钮

我试图弄清楚如何制作使用系统图标或图像图标的自定义导航栏按钮。我按照下面关于如何设置自定义导航栏背景和创建自定义文本按钮的教程进行操作,现在我想创建类似于教程中的按钮,但使用图标而不是文本。

http://idevrecipes.com/2010/12/13/wooduinavigation/

有人知道如何使用图标创建自定义导航栏按钮吗?

谢谢!



Best Answer-推荐答案


本教程正在使用 initWithCustomView: 创建一个 UIBarButtonItem 对象。基本上,您可以使用它来制作带有自定义图像的按钮。您所要做的只是使用自定义 View 创建一个 View 并将其作为 initWithCustomView: 的参数传递。

或者,更简单的是,创建一个包含自定义图像的 UIImage 对象,然后使用 initWithImage:target:action 创建一个 UIBarButtonItem 对象,例如,

UIBarButtonItem *newBarButton = [[UIBarButtonItem alloc] initWithImage: yourImage
                                                                target: self
                                                                action: @selector(buttonPressed) ];
self.navigationItem.leftBarButtonItem =  newBarButton;
[newBarButton release];

关于iphone - 使用系统图标或图像图标的自定义导航栏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5053728/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4