作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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;
}
上面的代码是这样的:
下面是我将 stuffInTopLeftCorner 更改为 YES 时的样子:
似乎在标题左侧添加内容根本不会导致所述标题移动。
我的问题是——这是否意味着它总是将标题居中,而不管它两边发生了什么?
最佳答案
据我所知,是的,它总是将标题居中,假设这是可能的。
关于ios - UIBarButtonSystemItemFlexibleSpace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751468/
Apple 文档是这样说的: UIBarButtonSystemItemFlexibleSpace在其他项目之间添加的空白。空间在其他项目之间平均分配。设置此值时将忽略其他项目属性。 说的有点模糊(到
我是一名优秀的程序员,十分优秀!