gpt4 book ai didi

iphone - iOS:如何为导航栏中的按钮添加边框图像?

转载 作者:行者123 更新时间:2023-11-29 13:26:47 25 4
gpt4 key购买 nike

我想在我的导航栏中添加一个栏按钮项,并给它一些看起来像垂直线的边框图像(在下图中用红色圈出)...

enter image description here

barbutton 项的背景将被清除,因为我将单独设置整个导航栏的背景图像。文本将是动态的,所以我无法将文本或线条烘焙到背景图像中,然后为条形按钮项目设置该背景图像。我只需要在栏按钮项的任一侧添加这些垂直线图像。

非常感谢您的智慧!

最佳答案

您可以使用可拉伸(stretch)的 UIImage 作为 UIButton 的背景,然后使用 UIButton 作为自定义 View 初始化条形按钮项目:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *bgImg = [[UIImage imageNamed:@"ButtonBorder.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)]; // or whatever size suits your needs
[btn setBackgroundImage:bgImg forState:UIControlStateNormal];

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:btn];

等等

关于iphone - iOS:如何为导航栏中的按钮添加边框图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12942710/

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