let btn = UIButton(frame: CGRect.zero)
btn.setImage(..., for: UIControlState.normal)
addSubview(btn)
btn.translatesAutoresizingMaskIntoConstraints = false
btn.rightAnchor.constraint(equalTo: btn.superview!.rightAnchor, constant: -32).isActive = true
btn.topAnchor.constraint(equalTo: btn.superview!.topAnchor, constant: 6 + vc.view.safeAreaInsets.top).isActive = true
btn.widthAnchor.constraint(equalToConstant: 32)
btn.heightAnchor.constraint(equalToConstant: 32)
btn.backgroundColor = .black //to check the rect
图像的大小是16x16。按钮应至少大两倍(因为接触面积小)。
width==16
height==22
.
同时,距离约束正常工作。
那我犯了什么错?或者我必须使用适合按钮1:1的图像资源?