gpt4 book ai didi

iphone - 自定义 uibarbuttonitem 图像与背景混合

转载 作者:行者123 更新时间:2023-12-01 17:33:20 25 4
gpt4 key购买 nike

我正在为导航栏制作自定义 UI,并且我有一个与这篇文章中提出的问题完全相同的问题

Custom background/transparent background on UIBarButtonItem?

在 StoryBoard 中,我尝试了各种组合以使我的 UIbarbuttonitem 着色为透明或清晰的颜色,但我仍然看到这个丑陋的黑色按钮(请参阅 + 符号)。如何实现透明效果,让按钮看起来与背景融为一体?

我的截图

enter image description here

其他一些应用截图。看看这看起来多漂亮?!

enter image description here

请注意,+ 图像是我自己的自定义 png img,大小为 20 x 20 像素,具有透明/空白背景。

最佳答案

您可以使用 iOS 5 中引入的新外观 API 来实现这一目标以及更多功能。

基本上,您只需为 UI 设置一次外观,它就会反射(reflect)在整个程序中。

这是 UIBarButtonItem 的示例:

// You can also use stretchable images
UIImage *image = [[UIImage imageNamed:@"myCoolBarButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

如果您不能使用 iOS 5,那么您必须像这样以编程方式构建它们:
// Create a custom button with an image
UIImage *image = [UIImage imageNamed:@"myCoolBarButton.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);

// Create a custom UIBarButtonItem with the button
UIBarButtonItem aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

无论如何,这里有一些关于外观主题的好教程的链接

User Interface Customization in iOS 5

How To Make Your App Stand Out With The New iOS 5 Appearance API

编辑:
只是为了澄清,使用自定义图像比使用颜色、渐变和透明度要容易得多。

关于iphone - 自定义 uibarbuttonitem 图像与背景混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13091954/

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