collectionViewを使って対応した対応した絵文字を押したら、
テキストに反映されるような物を作ろうとしています。
collectionViewCellに絵文字の流し込みまでは成功したのですが、
その先の部分がわからなかった為質問させていただきました。
swift
1import UIKit 2 3class thirdViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 4 5 @IBOutlet weak var text1: UITextField! 6 // スタンプの定義(Unicode) 7 let stamps = ["1F600", "1F601", "1F602", "1F603", "1F604", "1F605", "1F606", "1F606", 8 "1F607", "1F608", "1F609", "1F60A", "1F60B", "1F60C", "1F60D", "1F60E", "1F60F", 9 "1F610", "1F611", "1F612", "1F613", "1F614", "1F615", "1F616", "1F617", "1F618", 10 "1F619", "1F61A", "1F61B", "1F61C", "1F61D", "1F61E", "1F61F"] 11 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 16 17 } 18 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 19 // ★★★★★スタンプが押された時の処理を書く 20 //text1.text = ??? 21 } 22 23 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 24 return self.stamps.count //絵文字の数だけcollectionViewCellを作る 25 26 } 27 28 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 29 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) 30 if let label = cell.contentView.viewWithTag(1) as? UILabel { 31 // CollectionViewCellのUILabelを取得し、絵文字をに代入する 32 let text = UnicodeScalar(Int(self.stamps[indexPath.row], radix: 16)!) 33 label.text = text?.description 34 } 35 36 return cell 37 } 38 39} 40
絵文字をクリックしたらその下に配置してあるテキストの中に対応する絵文字を入力したいのですが、
★★★★★の部分に入力するべきコードがわかりませんでした。
どなたかお力をお貸しください。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/15 09:41
2019/08/15 09:52