์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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
- BFS
- realm
- RxSwift
- visionOS
- SnapKit
- MVVM
- ios
- XCTest
- Swfit
- BOJ
- designpattern
- combine
- UIKit
- tableView
- node.js
- arkit
- CollectionView
- ํ๋ก๊ทธ๋๋จธ์ค
- rxcocoa
- TCA
- Xcode
- raywenderlich
- Lv2
- Kuring
- SwiftUI
- ํจ์คํธ์บ ํผ์ค
- swift
- ๋ฐฑ์ค
- reactorkit
- Flutter
Archives
- Today
- Total
lgvv98
[SwiftUI] ViewModifier ๋ณธ๋ฌธ
ViewModifier
โ ๊ณต์๋ฌธ์
https://developer.apple.com/documentation/swiftui/viewmodifier
Apple Developer Documentation
developer.apple.com
โ ๊ณต์๋ฌธ์์ ์ผ๋ถ
โ ์ด๋ฅผ ํตํด์ ์ค๋ณต๋๋ ์ฝ๋๋ฅผ ์ฝ๊ฒ ์ค์ผ ์ ์์ต๋๋ค.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 50){
Text("Hello, world!")
.modifier(MyRoundedText()) // modifier๋ฅผ ํ์ฉ
Text("Hello, world!")
.myRoundedTextStyle()
Image(systemName: "pencil") // ํจ์๋ฅผ ํ์ฉ
.myRoundedTextStyle()
Rectangle()
.frame(width: 100, height: 100)
.myRoundedTextStyle()
}
}
}
// ๋ทฐ๋ฅผ ๊พธ๋ฉฐ์ฃผ๋ ๋ชจ๋ํ์ด์ด
struct MyRoundedText: ViewModifier {
func body(content: Content) -> some View { // content๋ ๋ด๊ฐ ๋ฐ์์จ ์์ฑ์ ๋ํ ์ ๋ณด
content
.font(.largeTitle)
.padding()
.background(Color.init(#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)))
.cornerRadius(20)
.padding()
.overlay(
RoundedRectangle(cornerRadius: 25).stroke(lineWidth: 10).foregroundColor(.blue)
)
}
}
extension View {
func myRoundedTextStyle() -> some View {
modifier(MyRoundedText())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
'apple > ๐ SwiftUI & Combine' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] State and Data Flow (0) | 2022.06.02 |
---|---|
[iOS] ํ๋ฉด ์คํฌ๋ฆฐ์ท ๋ฐ ๋ นํ ๊ฐ์ง (feat. SwiftUI) (0) | 2022.06.02 |
[SwiftUI] lazyVGrid (0) | 2022.05.25 |
[SwiftUI] menu (feat. Picker) (0) | 2022.05.25 |
[SwiftUI] Picker, segmentedStyle (feat. enum CaseIterable) (0) | 2022.05.23 |
Comments