ios - centerXAnchor 和 center.x 的区别

标签 ios constraints

据我所知,将元素水平居中的两种主要方法是使用以下技术:

1.

label.center.x = imageView.center.x

2.

label.centerXAnchor.constraint(equalTo: imageView.centerXAnchor)

这两种方法有什么区别?

最佳答案

1.下面设置一个label的frame

label.center.x = imageView.center.x

2.下面为标签设置自动布局约束

label.centerXAnchor.constraint(equalTo: imageView.centerXAnchor)

如果您不熟悉自动布局,请查看 Apple 的 Auto Layout Guide

关于ios - centerXAnchor 和 center.x 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43990488/

相关文章:

ios - 为什么@nonescaping 闭包不需要 [weak self]?

ios - For 循环中的 ObjC/ARC ByRef

ios - 让闪光灯与 AVFoundation Camera 一起工作

grails - 如何在多个列上使用唯一约束而不是创建复合键

ios - Xcode 8 约束

html - 谷歌地图在 iOS 上通过框溢出

ios - 取消选择行后如何取消突出显示 UITableView 中的附件?

join - Solr - 阻止具有许多子约束的父查询

constraints - Snowflake 的 Unique 约束有什么意义?

sql-server - 规则已被弃用,取而代之的是什么呢(TSQL)?