1 Import UIKit2 3 classVc1:uiviewcontroller {4 5Fileprivate LazyvarPickerv:uipickerview = {6Let V = Uipickerview (Frame:cgrect (x: -Y: -, Width: $, Height: -))7V.Delegate= Self8V.datasource = Self9V.backgroundcolor =. OrangeTen One returnv A }() - - OverrideFunc Touchesbegan (_ Touches:set<uitouch>, withEvent: Uievent?) { the View.addsubview (Pickerv) -Pickerv.showsselectionindicator =false - - } + } - + extension uiviewcontroller:uipickerviewdelegate, uipickerviewdatasource{ A PublicFunc numberofcomponents (inchPickerview:uipickerview)Int { at return 1 - } - - PublicFunc Pickerview (_ Pickerview:uipickerview, Rowheightforcomponent component:int)CGFloat { - return $ - } in PublicFunc Pickerview (_ Pickerview:uipickerview, Numberofrowsincomponent component:int)Int { - return Ten to } + - PublicFunc Pickerview (_ Pickerview:uipickerview, Viewforrow row:int, Forcomponent component:int, reusing View:uiview?)UIView { thepickerview.subviews[1].backgroundcolor =Uicolor.blue *pickerview.subviews[1].ishidden =false $pickerview.subviews[2].backgroundcolor =Uicolor.purplePanax Notoginsengpickerview.subviews[2].ishidden =false - the + ///The view between the two root lines ALet V =UIView () theV.frame = CGRect (x:0Y:0, Width: -, Height: -) +V.backgroundcolor =Uicolor.green - returnv $ } $}
Swift-code creation Pickerview Show or hide horizontal lines