gpt4 book ai didi

ios - UIBarButtonSystemItemFlexibleSpace

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

Apple 文档是这样说的:

UIBarButtonSystemItemFlexibleSpace在其他项目之间添加的空白。空间在其他项目之间平均分配。设置此值时将忽略其他项目属性。

说的有点模糊(到底什么空间是平均分配的?)所以我写了一个测试方法:

-(void) createToolbar {
BOOL stuffInTopLeftCorner = NO;
UIToolbar* bar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 1024, 44)];
self.bar = bar;
[self addSubview:bar];
UILabel* titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
titleLabel.text = @"Centered title";
titleLabel.font = [UIFont systemFontOfSize:30];
[titleLabel sizeToFit];
CGSize titleSize = [titleLabel bounds].size;
NSLog(@"titleSize is %g %g", titleSize.width, titleSize.height);
UIBarButtonItem* titleItem = [[UIBarButtonItem alloc]initWithCustomView:titleLabel];
UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UILabel* leftLabel = [[UILabel alloc]initWithFrame:CGRectZero];
leftLabel.text = @"Stuff in top left corner";
leftLabel.font = [UIFont systemFontOfSize:30];
[leftLabel sizeToFit];
UIBarButtonItem* topLeftCornerItem = [[UIBarButtonItem alloc]initWithCustomView:leftLabel];
NSMutableArray* items = [NSMutableArray arrayWithObjects: flexibleSpace, titleItem, flexibleSpace, nil];
if (stuffInTopLeftCorner) {
[items insertObject:topLeftCornerItem atIndex:0];
}
bar.items = items;
}

上面的代码是这样的:

enter image description here

下面是我将 stuffInTopLeftCorner 更改为 YES 时的样子:

enter image description here

似乎在标题左侧添加内容根本不会导致所述标题移动。

我的问题是——这是否意味着它总是将标题居中,而不管它两边发生了什么?

最佳答案

据我所知,是的,它总是将标题居中,假设这是可能的。

关于ios - UIBarButtonSystemItemFlexibleSpace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751468/

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