ios - Auto fit all UICollectionViewCell from data source to screen without scrolling -


i've array of uicolor's in data source, i'm trying fit cells' size can seen on screen without scrolling.

i don't know how it, far i've:

#pragma mark <uicollectionviewdatasource>  - (nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview {     return 1; }  - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section {     return self.datasource.count; }  - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {     uicollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:reuseidentifier forindexpath:indexpath];      // configure cell     uicolor *cellcolor = (uicolor *)self.datasource[indexpath.row];     cell.backgroundcolor = cellcolor;      (uiview *view in cell.contentview.subviews) {         if ([view iskindofclass:[uiimageview class]]) {             if ([[(uiimageview *)view image] isequal:[uiimage imagenamed:@"v_bg.png"]]) {                 [view removefromsuperview];             }         }     }      if ([cellcolor isequal:self.existingcolor]) {         uiimageview *img = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"v_bg.png"]];         img.frame = cgrectmake(0, 0, 30, 30);         img.center = cell.contentview.center;         img.backgroundcolor = [uicolor clearcolor];         [cell.contentview addsubview:img];     }      return cell; }  #pragma mark <uicollectionviewdelegate>  - (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath {         [[nsnotificationcenter defaultcenter] postnotificationname:uicolordidchangenotification                                                         object:[nsstring stringwithformat:@"%ld", (long)indexpath.row]];      [self.navigationcontroller popviewcontrollerretro]; }  #pragma mark collection view layout things  // layout: set cell size - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath {     cgfloat fixsize = ([uiscreen mainscreen].bounds.size.width / 3) - 2;     return cgsizemake(fixsize, fixsize); }  - (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout minimuminteritemspacingforsectionatindex:(nsinteger)section {     return 2; }  - (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout minimumlinespacingforsectionatindex:(nsinteger)section {     return 2; }  - (uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout insetforsectionatindex:(nsinteger)section {     return uiedgeinsetsmake(0, 0, 0, 0); } 


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -