기본 콘텐츠로 건너뛰기

4월, 2022의 게시물 표시

SwiftUI, TextField, 入力制限、英数字

  英数字のみ TextField ( "Input" , text : $input ) . onChange ( of : input , perform : filter ) func filter ( value : String ) {         let validCodes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"         let sets = CharacterSet ( charactersIn : validCodes)          input  = String (value. unicodeScalars . filter (sets. contains ). map ( Character . init ))                  if 10 < input . count {             input = String ( input . prefix ( 10 ))         }     } https://zenn.dev/yorifuji/articles/swiftui-textfield-filter

SwiftUI, half modal

 https://zenn.dev/oka_yuuji/articles/6b5d8ca2917707      @State var show = false     @State var showFull = false     @State var position = CGSize . zero     @State var viewSize = UIScreen . main . bounds     @State var higthRate = 0.35                ZStack {                 Rectangle ()                     . foregroundColor (. yellow )                 VStack {                     RoundedRectangle ( cornerRadius : 10 )                         . frame ( width : 60 , height : 5 )                         . padding (. top )                     Spacer ()                 }             }             . cornerRadius ( 20 )             . offset ( y : show ? viewSize . height * 0.4 : viewSize . height )             . offset ( y : position . height )             . animation (. timingCurve ( 0.2 , 0.8 , 0.2 , 1 , duration : 0.9 ), value : show ) +背景 if ( showModal ) {                                                  Button {                             showModal  = false      

SwiftUI, TextEditor placeholder

  ZStack {                                 VStack {                                     Text ( "PlaceHolder" )                                         . foregroundColor ( .gray )                                         . frame ( maxWidth : . infinity , alignment : . topLeading )                                         . padding (. top , 10 ). padding (. leading , 10 )                                                                      Spacer ()                                                                  }                             TextEditor ( text : $txt )                                 . frame ( maxWidth : . infinity , maxHeight : 80 )                                 . frame ( height : 60 )                                 . padding (. horizontal , 5.0 )                                 . opacity ( txt . isEmpty ? 0.25 : 1 )                             }                             . overlay ( RoundedRectangle ( cornerRadius : 5.0 )                              

SwiftUI, UT, ViewInspector

*** ViewInspector https://github.com/nalexn/ViewInspector/blob/master/guide.md *** import Lib https://www.raywenderlich.com/30227776-swiftui-testing-with-viewinspector-for-ios *** build error after lib import https://developer.apple.com/forums/thread/676682 ->  Creating a brand new test target fixed this.

SwiftUI, circle button

                                      Button ( action :{                                              }){                         Text ( "?" )                             . frame ( width : 30 , height : 30 )                             . background ( Color ( Const . BTN_COLOR ))                             . font (. title ). foregroundColor (. white ). clipShape ( Circle ())                                              }                     . buttonStyle ( PlainButtonStyle ())