본문 바로가기

2022/09

(19)
14 ~ 15. TextField & TextField Style & TextEditor TextField Apple Developer Documentation developer.apple.com TextField는 한 줄 입력에 최적화된 View이다. struct LabelView: View { @State private var value = "" var body: some View { Form { Text("testing") .padding() TextField("title", text: $value, prompt: Text("prompt1")) .padding() TextField("title", text: $value) .padding() } } } 생성자의 기본 파라미터는 세 개로 아래와 같다. title iOS와 iPadOS에서 placeholder로 사용된다. macOS에서 La..
13. Label & Font Label Apple Developer Documentation developer.apple.com Label은 이미지와 문자열을 표시하기에 적합한 View다. SwiftUI 초기에는 존재하지 않았기 때문에 하위 호환성을 고려해 사용해야 한다. struct LabelView: View { var body: some View { Label("Bulb", systemImage: "lightbulb") } } 기본 형태는 title + systemImage이고, Custom은 title + iCon으로 이 경우엔 Image View와 Text View를 조합해 사용하는 것과 크게 다르지 않다. struct LabelView: View { var body: some View { NavigationView { B..
사라진 'Info.plist' 파일 다시 만들기 프로젝트를 생성하거나 기존에 생성된 프로젝트를 사용하려는 경우 필요한 'Info.plist' 파일이 보이지 않는 경우가 있다. 문제를 해결해 보자 해결법은 간단하다. Project > Targets > Info 로 접근한 뒤 Key에 'App Transport Security Settings'를 추가하고 하위에 'Allow Arbitrary Loads'를 추가한다. Value는 'YES'로 설정한다. 짠, 간단하게 'Info.plist' 파일이 다시 나타났다.
12. Text Text 문자열을 표시하는 가장 기초적인 View이지만 기능이 꽤나 많은 편에 속한다. Locailzed String Localizable 파일 생성하기 프로젝트 내에 'Strings File'을 생성하고, 이름을 Localizable로 변경한다. 다른 이름을 사용하지 않는 것이 좋다. Localizable 파일 적용하기 프로젝트의 설정에서 Localizations를 찾아 원하는 언어를 추가한다. 이때 우측 상단의 검색을 이용하면 편리하다. Base와 English가 기본으로 적용돼 있다. 앞서 생성한 Localizable.strings 파일을 선택한 뒤 File Inspector에서 'Localize...' 버튼을 누른다. 아무 언어나 선택해 Localize를 누르면 이전에 눌었던 Localize.....
애플의 locale identifier Localization 등으로 종종 쓰인다. BCP 47 code를 기반으로 하고 있으며, 어떤 언어가 있는지, 어떻게 표현하는지는 다음과 같다. BCP 47 ar-SA Arabic Saudi Arabia (사우디 아라비아) cs-CZ Czech Czech Republic (체코) da-DK Danish Denmark (덴마크) de-DE German Germany (독일) el-GR Modern Greek Greece (그리스) en-AU English Australia (오스트레일리아) en-GB English United Kingdom (영국) en-IE English Ireland (아일랜드) en-US English United States (미국) en-ZA English South Afric..
10 ~ 11. Sheet / FullScreenCover & Popover Sheet / FullScreenCover Sheet는 화면을 Modal 방식으로 표시한다. Modal은 화면 전체를 채우는 Full Screen Modal과 화면의 일부를 채우는 Sheet, Card, Card Modal 방식이 있다. Sheet는 화면에 표시될 때 아래에서 위로 올라오는 Present 방식으로 표시되고, 사라질 때 위에서 아래로 사라지는 Dismiss 방식으로 사라진다. struct Nav_Sheet: View { @State private var statusMessage = "" @State private var sheetState = false var body: some View { VStack { Text(statusMessage) .font(.largeTitle) Button(..
08 ~09. Alert & Confirmation Dialog Alert SwiftUI로 Alert를 표시하는 데에는 준비물이 하나 필요하다. struct View_Alert: View { @State private var result = "" @State private var alertStat = false var body: some View { VStack { Text(result) .font(.largeTitle) Button(action: { }, label: { Text("Show Alert") }) .padding() } } } 바로 State Variable로 위의 코드에서는 alertStat이라는 이름을 가진다. alert은 해당 변수를 조작하여 자신의 상태를 변경하는데 사용하기 때문에 반드시 필요하다. struct View_Alert: View { ..
07. Overlay Overlay View 위에 View를 덮는 View다. struct View_Group: View { var body: some View { ScrollView(.vertical, showsIndicators: false) { VStack { RoundedRectangle(cornerRadius: 15) .frame(width: 300, height: 300) .foregroundColor(.yellow) .overlay { RoundedRectangle(cornerRadius: 15) .frame(width: 100, height: 100) .foregroundColor(.red) } } ZStack { RoundedRectangle(cornerRadius: 15) .frame(width: 300, ..
05 ~ 06. Scroll View & Form Scroll View struct View_Group: View { var body: some View { VStack { Group { Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") } .font(.largeTitle.bold()) .foregroundColor(.red) Group { Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!") Text("Hello, World!"..
03 ~ 04. Spacer & Group Spacer struct View_Spacer: View { var body: some View { VStack(spacing: 0) { HStack { Image(systemName: "suit.heart.fill") .resizable() .frame(width: 70, height: 70) .foregroundColor(.white) } .padding() .background(Color.blue) Spacer() VStack { Image(systemName: "suit.spade.fill") .resizable() .frame(width: 70, height: 70) .foregroundColor(.white) } .padding() .background(Color.red) } } } Space..