ios - Swift UICollectionViewCell resize with content -


i have problem uicollectionviewcell , hard newbie me. need help. working on dictionary. have search bar, collection view, labels , text view. can not resize neither collection view cell nor text view when showing search results.

view controller:

import uikit  class sozlukcontroller: uiviewcontroller, uisearchbardelegate, uicollectionviewdatasource, uicollectionviewdelegate{     @iboutlet var wordsearchbar: uisearchbar!     @iboutlet var collection: uicollectionview!     var worddatalist = [string]()     var meaningdatalist = [string]()     var dictionarydatalist = [string]()     var yeardatalist = [string]()      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      override func viewdidload() {         super.viewdidload()     }      func searchbarsearchbuttonclicked(searchbar: uisearchbar)  {         worddatalist = []         meaningdatalist = []         dictionarydatalist = []         yeardatalist = []         var word = searchbar.text         var parser:dictxmlparser = dictxmlparser()         var searchresults:[dictxmlresponse]=parser.beginparsing(1, searchtype: 1, searchword: word)          result in searchresults {             worddatalist.append(result.word)             meaningdatalist.append(result.meaning)             dictionarydatalist.append(result.dictionary)             yeardatalist.append(result.year)         }         searchbar.resignfirstresponder()         searchbar.text=""          collection.reloaddata()      }        func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {         return worddatalist.count     }      func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {         let cell:meaningcollectionviewcell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! meaningcollectionviewcell         cell.wordlabel.text = worddatalist[indexpath.row]         cell.meaningtext.text = meaningdatalist[indexpath.row]         cell.dictionarylabel.text = dictionarydatalist[indexpath.row]         return cell     }   } 

uicollectionviewcell:

import uikit  class meaningcollectionviewcell: uicollectionviewcell , uitextviewdelegate{     @iboutlet var wordlabel: uilabel!     @iboutlet var meaningtext: uitextview!     @iboutlet var dictionarylabel: uilabel!      override func  layoutsubviews() {         super.layoutsubviews()         let fixedwidth = meaningtext.frame.size.width         let newsize = meaningtext.sizethatfits(cgsize(width: fixedwidth, height: cgfloat.max))         meaningtext.frame.size = cgsize(width: max(newsize.width, fixedwidth), height: newsize.height)      }  } 

when wrote "gamze" in search bar "first" time, did not see entire meaning because of text view height.

screenshot of first search

surprisingly when wrote same word second search, text view height increased , covered following label. again not see entire meaning because of uicollectionviewcell height.

screenshot of second search

i set scrollable "false" , auto layout "on" through interface builder. there way know show meaning in textview not cover label , resize collection view cell according content

i having trouble finding sources swift. if can appreciate it.

i found great solution on github. trick creating xib file cell content

https://github.com/honghaoz/dynamic-collection-view-cell-with-auto-layout-demo


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -