【问题标题】:How to set the button created in the navigation bar as custom in iphone?如何将导航栏中创建的按钮设置为iphone中的自定义?
【发布时间】:2010-03-26 11:46:05
【问题描述】:

我是 iphone 开发新手。我在导航栏上创建了一个 UIBarButtonItem。我想将正确设置为自定义。 “样式:”属性没有自定义属性。请帮帮我。谢谢。

leftbutton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"LEFT.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftbutton)];
self.navigationItem.leftBarButtonItem = leftbutton;
[self.navigationItem]
[leftbutton release];

【问题讨论】:

    标签: iphone uibarbuttonitemstyle


    【解决方案1】:

    如果您只想在 Apple 的常用按钮框架内显示一个 .png 文件,那么您的代码就可以了。如果您的 png 文件未显示,请检查它是否有效。

    如果你想制作自己的按钮,可以使用-(id)initWithCustomView:(UIView *)customView

    查看这篇文章以获取有趣的示例代码: Custom Bar Button Sample Code

    【讨论】:

      【解决方案2】:

      您可以使用 - (id)initWithCustomView:(UIView *)customView 方法使用您想要的任何自定义视图创建项目。

      【讨论】:

        【解决方案3】:

        UIBarButtonItem 有 4 个初始化器,涵盖了您所需要的一切:

        • -initWithBarButtonSystemItem:target:action: 用于标准(内置项目);
        • -initWithTitle:style:target:action: 用于有标题但没有图片的按钮;
        • -initWithImage:style:target:action: 用于有图片但没有标题的按钮;
        • -initWithCustomView: 适用于任何 UIView 子类,Apple 的或您自己的。

        样式属性仅对标准按钮有意义。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-09-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多