Tabbas, ga cikakken bayyani na yadda zaku iya canza girman Canjin SwiftUI a cikin Swift.
SwiftUI shine tsarin Apple don gina mu'amalar masu amfani a duk fa'idodin Apple tare da ikon Swift. Wani lokaci, masu haษakawa na iya fuskantar buฦatar daidaita girman takamaiman abubuwan abubuwan UI, kamar sauyawa. Ta hanyar tsoho, SwiftUI baya bada izinin canza girman Canjawa kai tsaye, amma zamu iya amfani da wasu hanyoyin warwarewa don cimma wannan.
Mu nutse cikin maganin matsalar.
ฦirฦirar Maษalli na Musamman a cikin SwiftUI
Don daidaita girman Canjawa a cikin SwiftUI, hanya ษaya ita ce ฦirฦirar Canjawar al'ada. Wannan yana ba ku damar samun cikakken iko akan bayyanar da girman Sauyawa.
Ga misalin lambar da ke ฦirฦirar canjin al'ada:
struct CustomSwitch: View { @Binding var isOn: Bool var body: some View { Button(action: { self.isOn.toggle() }) { Rectangle() .fill(self.isOn ? Color.green : Color.gray) .frame(width: 50, height: 30) .overlay(Circle() .fill(Color.white) .offset(x: self.isOn ? 10 : -10), alignment: self.isOn ? .trailing : .leading) .cornerRadius(15) .animation(.spring()) } } }
Fahimtar Lambar Canjawa ta Musamman
Bari mu karya abin da wannan lambar ke yi:
- Tsarin CustomSwitch: Wannan yana bayyana kallon SwiftUI na al'ada. Yana da ษaure zuwa ฦimar boolean - jihar don sauyawa.
- Ayyukan maษalli: Wannan toshe lambar Swift yana ฦayyadaddun halayen lokacin da aka danna maษallin. Anan, kawai kunna yanayin โisOnโ.
- Rectangle: Misali na tsarin Rectangle na SwiftUI, yana bayyana kaddarorin siffa.
- Cika Launi: Launin Rectangle ya dogara da ko "isOn" gaskiya ne ko karya.
- frame: Mai gyara firam anan yana bayyana faษi da tsayin canjin al'ada.
- Mai rufi: Mai gyara mai rufi yana ba ku damar shimfiษa wani Duban SwiftUI a saman wanda yake akwai - a nan, farin Circle wanda ke aiki azaman maษallin sauyawa.
- Biya diyya: Ana amfani da gyare-gyaren kashewa anan don matsar da Da'irar dangane da ko "isOn" gaskiya ne ko na ฦarya, yana ba da tunanin cewa sauyawa yana juyawa.
- kusurwaRadius: Wannan ya shafi zagaye zuwa kusurwoyin Maษaukaki na ฦarฦashinsa.
- rayarwa: Mai canza motsin rai yana amfani da raye-rayen bazara () zuwa duka Maษalli - don haka lokacin da kuka canza, zai kunna sumul.
wrapping Up
Samun ikon keษance girman SwiftUI Canjawa na iya zama fa'ida yayin keษanta ฦirar mai amfani don dacewa da takamaiman bukatun aikace-aikacen. Mun koyi hanya ษaya don cimma wannan ta hanyar ฦirฦirar Sauyawa ta al'ada. Happy codeing!
Ka tuna: SwiftUI yana da sauฦin sassauฦa kuma ana iya daidaita shi. Jin kyauta don daidaita dabi'u da kaddarorin da ke cikin lambar da ke sama don dacewa da aikin ku da buฦatun ฦira. Idan kuna buฦatar canza girman kowane kayan haษin UI, ana iya amfani da tsarin ฦirฦirar al'ada ta hanya ษaya.