gpt4 book ai didi

ios - UIBarbuttonItem 在 ios 7 上没有标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:03 25 4
gpt4 key购买 nike

我有一个应用程序,我正在将其迁移到 iOS 7。但是,UIBarbuttonItem 没有标题,但工作正常。这是我的代码:

UIBarButtonItem * uibbShare = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sharewhite.png"] style:UIBarButtonItemStylePlain target:self action:@selector(sharePressed:)] autorelease];
// uibbShare.width = 56.0; // uncommenting this doesn't change anything
uibbShare.title = @"Share";

然后我将其中一些添加到工具栏,中间有一些灵活的空间项。

...
[items addObject:flex2];
[items addObject:uibbShare];
...

[self.toolbar setItems:items animated:NO];

在 iOS 7 上它们根本没有标题,在 iOS6 上一切正常。你不能再在 ios7 中创建这样的条形按钮了吗?

更新 开发论坛上同样的问题:

UIBarButtonItem can't have both title and image?

What happened to the text under toolbar icons?

编辑:(7 对 6)

enter image description here

编辑2:(来自Reveal的图片,文字好像没了,frame/bounds都是0.wtf)

enter image description here

最佳答案

最终为 UIBarButtonItems 创建了自定义 View 。这不是很好,但它会暂时起作用。我只是将旧的 UIBarButtonItems 传递给此函数,它会返回一个新的。

注意:如果有标题,我只是向上移动按钮的图像并在下面添加一个简单的标签,实际上并没有搞乱 titleEdgeInsets 和 centering 。另外,我将宽度设置为默认的 56。

-(UIBarButtonItem *)convertToButton:(UIBarButtonItem *)original
{
if ( SYSTEM_VERSION_LESS_THAN(@"7.0"))
return original;

CGFloat textFieldHeight = 13.f;
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 56, self.toolbar.frame.size.height);
button.showsTouchWhenHighlighted = YES;
[button setImage:original.image forState:UIControlStateNormal];
[button addTarget:original.target action:original.action forControlEvents:UIControlEventTouchUpInside];
button.tag = original.tag;

UIView * wr = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 56, self.toolbar.frame.size.height)] autorelease];
[wr addSubview:button];
wr.backgroundColor = [UIColor clearColor];

if (original.title != nil)
{
button.imageEdgeInsets = UIEdgeInsetsMake(-7, 0, 0, 0);
UILabel * l = [[[UILabel alloc] initWithFrame:CGRectMake(0, self.toolbar.frame.size.height - textFieldHeight, 56, textFieldHeight)] autorelease];
l.font = [UIFont systemFontOfSize:11.f];
l.backgroundColor = [UIColor clearColor];
l.textColor = [UIColor lightGrayColor];
l.textAlignment = UITextAlignmentCenter;
l.text = original.title;
[wr addSubview:l];
}

UIBarButtonItem * theNew = [[[UIBarButtonItem alloc] initWithCustomView:wr] autorelease];
theNew.tag = original.tag;
theNew.width = 56;
return theNew;

}

关于ios - UIBarbuttonItem 在 ios 7 上没有标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19134598/

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