-
[SwiftUI] scaledToFill vs scaledToFit와 frame의 순서Swift/SwiftUI 2023. 11. 19. 18:33
scaledToFill vs scaledToFit
scaledToFill vs scaledToFit ⚠️ 순서에 유의! scaledToFill이 먼저 와야함
HStack{ KFImage(URL(string: feed.profileImage)) .resizable() .clipShape(Circle()) //순서에 유의! .frame(width: .screenWidth*0.13, height: .screenWidth*0.13) .scaledToFill() .border(.black) Text("\(feed.creatorID)") Spacer() }
먼저 이미지를 조정하고 사이즈를 잘라준다.
HStack{ KFImage(URL(string: feed.profileImage)) .resizable() .clipShape(Circle()) //scaledToFill이 먼저 와야함 .scaledToFill() .frame(width: .screenWidth*0.13, height: .screenWidth*0.13) .border(.black) Text("\(feed.creatorID)") Spacer() }
frame(width:height:alignment:)
Positions this view within an invisible frame with the specified size.: 지정된 크기로 보이지 않는 프레임 내에 이 뷰를 배치합니다.⚠️먼저 이미지를 비율에 맞춰 자르고(scaledToFill) 프레임(frame)을 배치할 것
'Swift > SwiftUI' 카테고리의 다른 글
[SwiftUI]연속되는 뷰 넘기는 상황에서 이미지, 텍스트의 길이가 달라져서 위치가 고정되지 않는 문제 (1) 2023.12.05 [SwiftUI] zstack button not working, ZStack에서의 버튼 동작, zIndex() (0) 2023.11.24 [SwiftUI] list에서 가장자리 여백 제거, 구분선 제거 (0) 2023.11.19 Zstack에서 버튼이 중첩해서 눌리는 현상(position vs offset) (0) 2023.10.01 Property Wrapper (0) 2023.09.28