如何将导航栏中创建的按钮设置为iPhone中的自定义按钮?

发布于 2024-08-26 11:13:18 字数 371 浏览 12 评论 0原文

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

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

I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I want to set the proper to custom. There is no property as custom for "style:" attribute.Please help me out.Thanks.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仲春光 2024-09-02 11:13:18

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

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

查看这篇文章以获取有趣的示例代码:
自定义栏按钮示例代码

If you just want to display a .png file inside the usual button frame from Apple, then your code is ok. If your png file is not displaying, just check if it's valid.

If you want to make your own button, you can use -(id)initWithCustomView:(UIView *)customView

Check this post for an interesting sample code :
Custom Bar Button Sample Code

不寐倦长更 2024-09-02 11:13:18

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

You can create item with - (id)initWithCustomView:(UIView *)customView method with whatever custom view you want.

暮色兮凉城 2024-09-02 11:13:18

UIBarButtonItem 有 4 个初始值设定项,涵盖了您所需要的所有内容:

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

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

UIBarButtonItem has 4 initializers which cover all you will ever need:

  • -initWithBarButtonSystemItem:target:action: for standard (built-in items);
  • -initWithTitle:style:target:action: for buttons with title and no image;
  • -initWithImage:style:target:action: for buttons with image and no title;
  • -initWithCustomView: for any UIView subclass, Apple's or your own.

The style property makes sense only for standard buttons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文