布局中的系统间距是多少? 第一个问题的答案:回答第二个问题:

问题描述

我很难理解视图之间的“系统间距”或“标准间距”。

http
    .authorizeRequests(authorize -> authorize
        .mvcMatchers("/path/{name}").access("@webSecurity.checkName(authentication,#name)")
        ...
    );

我注意到,如果我替换以下内容,则会有所不同:

import UIKit
import PlaygroundSupport

let rootView = UIView(frame: CGRect(x: 100,y: 100,width: 500,height: 500))
rootView.backgroundColor = .white

let containerView = UIView(frame: CGRect(origin: .zero,size: .init(width: 300,height: 200)))
containerView.backgroundColor = .yellow
rootView.addSubview(containerView)

let button = UIButton()
button.setTitle("Button",for: .normal)
button.backgroundColor = .red
containerView.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    button.widthAnchor.constraint(equalToConstant: 100),button.leadingAnchor.constraint(equalToSystemSpacingAfter: containerView.leadingAnchor,multiplier: 1)
])

PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = rootView
在按钮位置button.leadingAnchor.constraint(equalTo: containerView.leadingAnchor)

。另外,equalToSystemSpacingAfter如何适应文本大小的变化?

解决方法

第一个问题的答案:

constraint(equalTo:.constraint(equalToSystemSpacingAfter:之间的差异

enter image description here enter image description here

回答第二个问题:

还,equalToSystemSpacingAfter如何适应文本大小的变化?

由于您使用的是100点的固定宽度,因此如果按钮标题的长度增加,它将被简单地截断。要解决此问题,应避免设置确切的宽度。