@@ -15,155 +15,8 @@ class EmoticonViewController: UIViewController {
1515
1616 let screenW = UIScreen . main. bounds. size. width
1717 let screenH = UIScreen . main. bounds. size. height
18- let height : CGFloat = 300
19- let emoticonView = EmoticonView . init ( frame: CGRect . init ( x: 0 , y: screenH - height, width: screenW, height: height) )
18+ let height : CGFloat = 400
19+ let emoticonView = EmoticonView . init ( frame: CGRect . init ( x: 0 , y: screenH - height - mSafeBottomMargin ( ) , width: screenW, height: height) )
2020 view. addSubview ( emoticonView)
21- emoticonView. backgroundColor = UIColor . red
22- }
23- }
24-
25-
26- class EmoticonView : UIView {
27- let segCtlView : LLSegmentedControl
28- var colView : UICollectionView !
29- var items = [ LLSegmentItemTitleImageTabBarItem] ( )
30-
31- var indexToList = [ Int: UIView] ( )
32- override init ( frame: CGRect ) {
33- let datas : [ ( title: String , imageStr: String , style: LLTitleImageButtonStyle ) ] = [
34- ( " 螃蟹 " , " watermelon " , LLTitleImageButtonStyle . titleEmty) ,
35- ( " 麻辣小龙虾 " , " lobster " , LLTitleImageButtonStyle . titleEmty) ,
36- ( " 苹果 " , " grape " , LLTitleImageButtonStyle . titleEmty) ,
37- ( " 营养胡萝卜 " , " crab " , LLTitleImageButtonStyle . titleEmty) ,
38- ( " 葡萄 " , " carrot " , LLTitleImageButtonStyle . titleEmty) ,
39- ( " 美味西瓜 " , " apple " , LLTitleImageButtonStyle . titleEmty) , ]
40- for (title, imageStr, diyStyle) in datas {
41- let tabBarItem = LLSegmentItemTitleImageTabBarItem . init (
42- title: title,
43- image: UIImage ( named: imageStr) ,
44- selectedImage: UIImage ( named: imageStr + " _selected " ) )
45-
46- tabBarItem. style = diyStyle
47- tabBarItem. setImageBlock = { ( imageView, isSelected, tabBarItem) in
48- imageView. image = isSelected ? tabBarItem. selectedImage ?? tabBarItem. image : tabBarItem. image
49- }
50- items. append ( tabBarItem)
51- }
52- let segFrame = CGRect . init ( x: 0 , y: 0 , width: frame. width, height: 40 )
53- segCtlView = LLSegmentedControl . init ( frame: segFrame, tabBarItems: items)
54-
55- let colFrame = CGRect . init ( x: 0 , y: segFrame. maxY, width: frame. width, height: frame. height - segFrame. height)
56- super. init ( frame: frame)
57-
58- segCtlView. backgroundColor = UIColor . lightGray. withAlphaComponent ( 0.2 )
59- segCtlView. indicatorView. shapeStyle = . background( color: UIColor . red, img: nil )
60- let titleViewStyle = LLSegmentItemTitleViewStyle ( )
61- var ctlViewStyle = LLSegmentedControlStyle ( )
62- ctlViewStyle. segmentItemViewClass = LLSegmentItemTitleImageView . self
63- ctlViewStyle. itemViewStyle = titleViewStyle
64- segCtlView. reloadData ( ctlViewStyle: ctlViewStyle)
65- addSubview ( segCtlView)
66- segCtlView. reloadData ( )
67-
68- colView = creatCol ( frame: colFrame)
69- addSubview ( colView)
70- segCtlView. associateScrollerView = colView
71- }
72-
73- required init ? ( coder: NSCoder ) {
74- fatalError ( " init(coder:) has not been implemented " )
75- }
76- }
77-
78- extension EmoticonView : UICollectionViewDelegate , UICollectionViewDataSource {
79- func collectionView( _ collectionView: UICollectionView , numberOfItemsInSection section: Int ) -> Int {
80- return items. count
81- }
82-
83- func collectionView( _ collectionView: UICollectionView , cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
84- let cell = collectionView. dequeueReusableCell ( withReuseIdentifier: " cell " , for: indexPath)
85- cell. contentView. backgroundColor = UIColor . init ( red: CGFloat ( arc4random ( ) % 256 ) / 255.0 , green: CGFloat ( arc4random ( ) % 256 ) / 255.0 , blue: CGFloat ( arc4random ( ) % 256 ) / 255.0 , alpha: 1 )
86- cell. contentView. viewWithTag ( 100 ) ? . removeFromSuperview ( )
87- if let view = indexToList [ indexPath. row] {
88- view. frame = cell. contentView. bounds
89- cell. contentView. addSubview ( view)
90- } else {
91- let newView = EmoticonListView . init ( frame: cell. contentView. bounds)
92- indexToList [ indexPath. row] = newView
93- newView. frame = cell. contentView. bounds
94- cell. contentView. addSubview ( newView)
95- newView. tag = 100
96- }
97- return cell
98- }
99-
100- func creatCol( frame: CGRect ) -> UICollectionView {
101- let viewWidth = self . bounds. width
102- let viewHeight = self . bounds. height
103-
104- let interitemSpacing : CGFloat = 22
105-
106- let contentInset = UIEdgeInsets ( top: 0 , left: 0 , bottom: 0 , right: 0 )
107- let itemSizeWidth : CGFloat = viewWidth
108- let layout = UICollectionViewFlowLayout ( )
109- layout. itemSize = CGSize ( width: itemSizeWidth, height: viewHeight)
110- layout. minimumInteritemSpacing = interitemSpacing
111- layout. minimumLineSpacing = 0
112- layout. scrollDirection = . horizontal
113-
114- let colView = UICollectionView ( frame: frame, collectionViewLayout: layout)
115- colView. delegate = self
116- colView. dataSource = self
117- colView. isPagingEnabled = true
118-
119- colView. backgroundColor = UIColor . clear
120- colView. register ( UICollectionViewCell . classForCoder ( ) , forCellWithReuseIdentifier: " cell " )
121- colView. contentInset = contentInset
122- return colView
123- }
124- }
125-
126-
127- class EmoticonListView : UIView , UICollectionViewDelegate , UICollectionViewDataSource {
128- var colView : UICollectionView !
129- override init ( frame: CGRect ) {
130- super. init ( frame: frame)
131- colView = creatCol ( frame: frame)
132- addSubview ( colView)
133- }
134-
135- required init ? ( coder: NSCoder ) {
136- fatalError ( " init(coder:) has not been implemented " )
137- }
138-
139- func creatCol( frame: CGRect ) -> UICollectionView {
140- let rowCount = 4
141- let viewWidth = self . bounds. width
142- let interitemSpacing : CGFloat = 22
143-
144- let contentInset = UIEdgeInsets ( top: 0 , left: 10 , bottom: 0 , right: 10 )
145- let itemSizeWidth : CGFloat = ( viewWidth - CGFloat( rowCount- 1 ) * interitemSpacing - contentInset. left - contentInset. right) / CGFloat( rowCount)
146- let layout = UICollectionViewFlowLayout ( )
147- layout. itemSize = CGSize ( width: itemSizeWidth, height: itemSizeWidth)
148- layout. minimumInteritemSpacing = interitemSpacing
149- layout. minimumLineSpacing = 33
150-
151- let colView = UICollectionView ( frame: frame, collectionViewLayout: layout)
152- colView. delegate = self
153- colView. dataSource = self
154- colView. backgroundColor = UIColor . clear
155- colView. register ( UICollectionViewCell . classForCoder ( ) , forCellWithReuseIdentifier: " cell " )
156- colView. contentInset = contentInset
157- return colView
158- }
159-
160- func collectionView( _ collectionView: UICollectionView , numberOfItemsInSection section: Int ) -> Int {
161- return 20
162- }
163-
164- func collectionView( _ collectionView: UICollectionView , cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
165- let cell = collectionView. dequeueReusableCell ( withReuseIdentifier: " cell " , for: indexPath)
166- cell. contentView. backgroundColor = . blue
167- return cell
16821 }
16922}
0 commit comments