본문 바로가기

Note

나만의 라벨 스타일 만들 때

SwiftUI Framework에서 제공하는 LabelStyle Protocol을 이용한다.

 

struct TrailingIconLabelStyle: LabelStyle {
    // LabelStyle 프로토콜을 따를 때 필수적으로 구현해줘야되는 거 1번
    func makeBody(configuration: Configuration) -> some View {
        // 수평으로 좌타이틀 우아이콘 설정을 해준다.
        HStack {
            configuration.title
            configuration.icon
        }
    }
}

 

https://developer.apple.com/documentation/swiftui/labelstyle

 

LabelStyle | Apple Developer Documentation

A type that applies a custom appearance to all labels within a view.

developer.apple.com

 

필수적으로 구현해줘야되는 거도 읽어보자.

makeBody 함수 구현

그리고 그걸 정의한 걸 어떤 View 내 Body와 연결이 돼야된다.

'Note' 카테고리의 다른 글

.map  (0) 2023.04.12
ForEach  (0) 2023.04.10
타입 프로퍼티  (0) 2023.04.07
익스텐션 (Extensions)  (0) 2023.04.06
self, Self  (0) 2023.03.29