gpt4 book ai didi

cocoa-touch - 使用自动布局视觉格式字符串均匀分布间距

转载 作者:行者123 更新时间:2023-12-04 09:04:00 34 4
gpt4 key购买 nike

b是否可以平均分配左右空间在 @"|-[a(5)]-[b(8)]-[c(5)]-|"使用视觉格式字符串?

最佳答案

苹果Auto Layout Guide建议使用“间隔 View ”。这是在水平方向上以相等的间距布置三个 View 的解决方案:

// create views dictionary
NSMutableDictionary *viewsDictionary = [NSMutableDictionary dictionary];
[viewsDictionary addEntriesFromDictionary:NSDictionaryOfVariableBindings(viewA, viewB, viewC)];

// create 4 spacer views
for (int i = 0; i < 4; i++) {
UIView *spacerView = [[UIView alloc] init];
spacerView.hidden = YES;
[self addSubview:spacerView];
[viewsDictionary setObject:spacerView
forKey:[NSString stringWithFormat:@"spacer%d", i + 1]];
}

// disable translatesAutoresizingMaskIntoConstraints in views for auto layout
[viewsDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
{
[obj setTranslatesAutoresizingMaskIntoConstraints:NO];
}];

// add constraints
[superview addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:
@"|[spacer1(>=0)][viewA][spacer2(==spacer1)][viewB][spacer3(==spacer1)][viewC][spacer4(==spacer1)]|"
options:kNilOptions
metrics:nil
views:viewsDictionary]];

请注意 spacer1的宽度设置为大于 0。随后的间隔 View 设置为与 spacer1 具有相同的宽度.

关于cocoa-touch - 使用自动布局视觉格式字符串均匀分布间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18042034/

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