[英]How do I programmatically place UILabel on UIImageview?
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
//I would like the profile Image View and the username button to be on the topAnchor of the postImageView. //我希望配置文件图像视图和用户名按钮位于 postImageView 的 topAnchor 上。 I don't know how to do this programmatically.
我不知道如何以编程方式执行此操作。 Maybe I have to make new constraints but I am not sure how to approach this.
也许我必须做出新的限制,但我不知道如何解决这个问题。 I would appreciate it if you could make edits to the code and let me know how to tackle this issue.
如果您可以对代码进行编辑并告诉我如何解决此问题,我将不胜感激。
addSubview(profileImageView)
profileImageView.anchor(top: topAnchor, left: leftAnchor,
paddingTop: 14, paddingLeft: 14)
profileImageView.setDimensions(height: 58, width: 58)
profileImageView.layer.cornerRadius = 58 / 2
addSubview(usernameButton)
usernameButton.centerY(inView: profileImageView,
leftAnchor: profileImageView.rightAnchor, paddingLeft: 10)
addSubview(optionsButton)
optionsButton.centerY(inView: profileImageView)
optionsButton.anchor(right: rightAnchor, paddingRight: 12)
addSubview(postImageView)
postImageView.anchor(top: profileImageView.bottomAnchor, left: leftAnchor, right: rightAnchor,
paddingTop: 10)
postImageView.heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1).isActive = true
addSubview(playerView)
playerView.anchor(top: profileImageView.bottomAnchor, left: leftAnchor, right: rightAnchor,
paddingTop: 8)
playerView.heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1).isActive = true
configureActionButtons()
addSubview(likesLabel)
likesLabel.anchor(top: likeButton.bottomAnchor, left: leftAnchor, paddingTop: -2,
paddingLeft: 10)
addSubview(captionLabel)
captionLabel.anchor(top: usernameButton.bottomAnchor, left: leftAnchor, right: rightAnchor,
paddingLeft: 10, paddingRight: 8)
addSubview(postTimeLabel)
postTimeLabel.anchor(top: captionLabel.bottomAnchor, left: leftAnchor, paddingLeft: 10)
}
This can be useful to you.这可能对您有用。
https://stackoverflow.com/a/39463981/6849145 https://stackoverflow.com/a/39463981/6849145
Found it on stackoverflow itself.在stackoverflow本身上找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.