ios - Image in ImageView issue Swift -


i have uicollectionviewcontroller class code :

class viewcontroller1: uicollectionviewcontroller  , uicollectionviewdelegateflowlayout{      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          self.collectionview?.backgroundcolor = uicolor(white: 0.95, alpha: 1)         self.collectionview?.alwaysbouncevertical = true         collectionview?.registerclass(cell.self, forcellwithreuseidentifier: "cellid")     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }     override func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {          return 1     }     override func  collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {          return collectionview.dequeuereusablecellwithreuseidentifier("cellid", forindexpath: indexpath)     }      func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize {           return cgsize(width: view.frame.width, height: 100)       }  }   class cell :uicollectionviewcell   {      //var : int = 0      override init(frame: cgrect) {          super.init(frame: frame)           self.setupviews()      }      required init?(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     }      var namelabel : uilabel = {          let label = uilabel()         label.text = "test"         //label.font = uifont.boldsystemfontofsize(14)         label.translatesautoresizingmaskintoconstraints = false         return label     }()      var distanzalabel : uilabel = {          let label = uilabel()         label.text = "200km"         //label.font = uifont.boldsystemfontofsize(14)         label.translatesautoresizingmaskintoconstraints = false         return label     }()      var imagev : uiimageview = {          let imageview =  uiimageview()          //imageview.frame = cgrectmake(0, 0, 450 , 150);         imageview.image = uiimage(named: "2.jpg")         imageview.contentmode = .scaleaspectfit         //imageview.clipstobounds = true         imageview.backgroundcolor = uicolor.greencolor()         imageview.translatesautoresizingmaskintoconstraints = false          return imageview       }()      var imagev1 : uiimageview = {          let imageview =  uiimageview()          imageview.frame = cgrectmake(0, 0, 20 , 20);         imageview.image = uiimage(named: "user male filled.png")         imageview.contentmode = .scaleaspectfit         //imageview.clipstobounds = true         imageview.backgroundcolor = uicolor.blackcolor()         imageview.translatesautoresizingmaskintoconstraints = false          return imageview       }()       func setupviews(){           backgroundcolor = uicolor.whitecolor()          self.addsubview(namelabel)         self.addsubview(distanzalabel)         self.addsubview(imagev)         self.addsubview(imagev1)          let lunghezza = self.frame.width         let result = lunghezza - 100          addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-0-[v0(\(lunghezza))]|", options: nslayoutformatoptions(), metrics: nil, views: ["v0" : imagev]))   addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-\(result)-[v0(30)]|", options: nslayoutformatoptions(), metrics: nil, views: ["v0" : imagev1]))         addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|-5-[v0(33)]-4-[v1]|", options: nslayoutformatoptions(), metrics: nil, views: ["v0" : imagev , "v1" : namelabel]))          addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|-5-[v0(33)]-4-[v1]|", options: nslayoutformatoptions(), metrics: nil, views: ["v0" : imagev , "v1" : imagev1]))        }} 

my problem when execute code :

http://postimg.org/image/jqwjt0o2f/

as can see image , 2 images small respect uiimageview 's size , , want example if have uiimageview' size 30x30 image fills imageview.

i select color 2 imageview show real size of uiimageview

how solve problem?

if 2 modes can fit want. fill , scale (or resize) mode.

fill mode : keep image can cut part of image. resize or scale mode : resize image fit image view


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -