我正在尝试将第一个正文视图中的Image
对齐到顶部,但是找不到解决方法。我想像在.top
中那样设置ZStack
的对齐方式,就像这样:
ZStack(alignment: .top) {
Image("imagename")
Text("Test")
}
在此代码中,图像前面的文本将在顶部。我该怎么做,但是图像是正文视图,文本是图像。
答案 0 :(得分:0)
"positives": 4, "total": 63, "sha256": "6f9c383bdf061c9ed7415c89474f1d04b9acec6af3cc87dd3aa394db9c6a7867"
"positives": 4, "total": 72, "sha256": "7b4aceaadd78ec496c6fd9a284d7411c5085f4efd156e7fe2bac0df872a01034"
"positives": 4, "total": 71, "sha256": "75503c537e8dc0b30c0fbc78a9b1dfc966ca7c97caa0142c38201ab7de1c0631"
"positives": 4, "total": 73, "sha256": "5a9f454578cf84e196346ed79b16f4614271c6748846b3f192cba2e39084ce55"
"positives": 4, "total": 73, "sha256": "de888d1402cc7347c22e53b660641789f5bb4ac73d6dc0eb054e3d813425c305"
"positives": 4, "total": 71, "sha256": "82e55e6abdd9d2a78db2cae8bbd048fcb0249651820aebbd7fcaadc6d5252bff"
"positives": 5, "total": 71, "sha256": "6d371555e08ba2b2397fd44a0db31605e7def831585c4c11dbb21c70d89e3b35"
"positives": 6, "total": 68, "sha256": "51350e36d2cef84097077a4f5f12e5ee359625ec0f776403895039c4442860fa"
"positives": 17, "total": 69, "sha256": "9968827ab119c8e8362c8a5cbef4389c2c36a08eda30ce091fe9a8e19f9eec0d"
"positives": 18, "total": 70, "sha256": "f57241e8c01595bc6f2abfdb0df3a8e4bbb5746009ff6063ab185587211cacef"
"positives": 55, "total": 71, "sha256": "0c802ce9e48b3c2e22b34f97090056de44ee1fca7da4f88c48f7b79f6280c187"
"positives": 35, "total": 70, "sha256": "9e06288e6ccdcf2d8394d297de6b1f9df6810c797e25fe20e42da64a4f8f1c2e"
"positives": 46, "total": 71, "sha256": "8454d6cb1603949423b9593bebc820a937bd90690094c6fabff25b11ca6ec98d"
"positives": 12, "total": 70, "sha256": "67bd4c84c0940a9f22baaadd35acd04a167ceb0280051666eaf4f8cef271a8b6"
"positives": 60, "total": 70, "sha256": "e374346869470dd4c26de8380c26cc6833e875456216aa624493f475e0c8e7e6"
"positives": 14, "total": 70, "sha256": "c5bd171025b10ba777008c349b26863a5259a7f45ad46ab71d9f227a2959ab83"
"positives": 61, "total": 71, "sha256": "7f7d3ede921b7dca9c12d97c5d770fe0c58a913d91fcfef942874ef9e535c38d"
"positives": 10, "total": 70, "sha256": "75e055f55d7130fbcee12c8d89a7a400eed7f59f131bb9d1a5f6909b7a776dc1"
"positives": 51, "total": 57, "sha256": "43b6eb575e89f4f4637c3cb979a1c9cd0af69a6aa13c98a9a44820e937f0d056"
"positives": 5, "total": 56, "sha256": "b351fd6c98acc5648184e9bb01152975c0fc98c1816d1441d042d9b76b9e207c"
"positives": 7, "total": 57, "sha256": "1802dd8641fa40ffeccd79888726a1fea579d8f9fd7fb1d23e0b1e91ddcd2867"
"positives": 53, "total": 56, "sha256": "bd75e387fca7ca6f3a2ad3403f2cd4adc55fa4fde69e5d8785edbe6c47e0aab1"
"positives": 57, "total": 62, "sha256": "494358b446fb61afcd7c9c871edb5cbfcbba33859a9bd7f47a553476bea3810b"
"positives": 6, "total": 66, "sha256": "891ba3880fa58a899ccf13e8f11104c7207c20f85a17d098bbef57824f6e4907"
"positives": 61, "total": 67, "sha256": "4b40543ac6cca09c48259171ea036b44ac51fb5aecfd7f27891b22d2d2c8cfe3"
"positives": 56, "total": 68, "sha256": "136e5b54c9751bf0cd2b07f73680ee5c152fe9de82c5a14764c0137e1793167a"
"positives": 31, "total": 68, "sha256": "8a84ab39bebb6a05ec3e430f76d43356b9778c9f80a3583efa7efd21a250748c"
"positives": 28, "total": 61, "sha256": "34240815dd9521a822cc3f2c3ceecbe1ad5ea81a725b8cce4e23978b118c6c2c"
"positives": 17, "total": 66, "sha256": "72baea57054415c69dbef9a303183e28946c33faeb354c3e849622dbf0d6da81"
(read more here)的另一种用途!
GeometryReader
答案 1 :(得分:0)
另一种替代方法是使用Spacer。
var body: some View {
VStack(alignment: .center) {
Image(systemName: "person")
Spacer()
}
}
我实际上写了blog post,内容涉及如何使用Spacer创建相当复杂的布局。