gpt4 book ai didi

iPhone SDK : How to add an image to a UIBarButton?

转载 作者:行者123 更新时间:2023-12-03 18:41:12 25 4
gpt4 key购买 nike

我使用下面的代码在导航栏上创建一个带有图像的按钮。

我可以看到图像,但我也可以看到图像周围按钮的边框。我的问题是,如何去掉按钮边框。我只想看到导航栏上的图像,没有边框。

UIBarButtonItem *settingsBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_prefs.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openSettings:)];
[[self navigationItem] setLeftBarButtonItem:settingsBtn];
[settingsBtn release];

提前致谢。任何指针、进一步阅读的链接或示例表示赞赏。

最佳答案

这是我当前项目之一的代码片段。它为 UIBarButtonItem 加载具有透明度的图像:

UIImage* image = [UIImage imageNamed:@"some-image.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setRightBarButtonItem:someBarButtonItem];
[someBarButtonItem release];
[someButton release];

关于iPhone SDK : How to add an image to a UIBarButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2924044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com