Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- MVVM
- 애니메이션
- UICollectionView
- ios
- Observable
- rxswift
- ribs
- swiftUI
- RxCocoa
- Xcode
- HIG
- 스위프트
- collectionview
- 클린 코드
- Refactoring
- Protocol
- combine
- clean architecture
- SWIFT
- Human interface guide
- 리팩토링
- map
- uitableview
- uiscrollview
- scrollview
- Clean Code
- tableView
- swift documentation
- 리펙토링
- UITextView
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - SwiftUI] ImagePaint 사용 방법 (#패턴 이미지) 본문
ImagePaint 란?
- ImagePaint는 이미지를 격자 무늬로 여러개 그릴때 사용하며, ShapeStyle를 준수하고 있는 형태
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@frozen public struct ImagePaint : ShapeStyle {
public var image: Image
public var sourceRect: CGRect
public var scale: CGFloat
public init(image: Image, sourceRect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1), scale: CGFloat = 1)
}
- shapeStype을 준수하고 있으므로 fill()이나 stroke()안에 ImagePaint() 인스턴스를 넣어서 사용이 가능
ImagePaint 사용 방법
- ShapeStyle을 준수하고 있으므로 fill, stoke에 사용
- fill()에 사용
RoundedRectangle(cornerRadius: 20) .fill(ImagePaint(image: Image("myImage"), scale: 0.2))
// 0.2 - myImage크기가 크므로 작도록 스캐일 조정

- stoke()에 사용
RoundedRectangle(cornerRadius: 20)
.stroke(ImagePaint(image: Image("myImage"), scale: 0.2), lineWidth: 30)

- stoke()에 sourceRect값을 주어서, stroke가 그럴듯하게 보이도록 사용
RoundedRectangle(cornerRadius: 20)
.stroke(
ImagePaint(
image: Image("myImage"),
sourceRect: CGRect(x: 0.3, y: 0.3, width: 0.5, height: 0.5),
scale: 1.0
),
lineWidth: 40
)
.frame(width: 300, height: 500)

* 전체 코드: https://github.com/JK0369/ExImagePaint
* 참고)
https://developer.apple.com/documentation/swiftui/imagepaint
https://medium.com/devtechie/imagepaint-in-swiftui-777f7fbe49ef
'iOS 기본 (SwiftUI)' 카테고리의 다른 글
Comments
jake-kim님의
글이 좋았다면 응원을 보내주세요!