iphone - UICollectionView and Custom Height -
i'm using uiviewcontroller inside uicollectionvieww, , searched on internet how can customize height of total uicollectionview. setup uicollectionview height >= 1 (i'm using autolayout) in .m file tried with:
uicollectionviewflowlayout *flowlayout = [[uicollectionviewflowlayout alloc] init]; [flowlayout setitemsize:cgsizemake(160, 160)]; [flowlayout setscrolldirection:uicollectionviewscrolldirectionvertical]; [flowlayout setminimuminteritemspacing:0]; [flowlayout setminimumlinespacing:0]; nsinteger itemcount = [self.collectionview numberofitemsinsection:0]; [flowlayout setitemsize:cgsizemake(self.collectionview.frame.size.width, 160 * itemcount)]; [self.collectionview setcollectionviewlayout:flowlayout]; nslog(@"%f", self.collectionview.frame.size.height);
but in nslog still show me height 1...how can setup height of uicollectionview custom height(that based on element in section * 160). suggest ? thanks.
edit: create cells:
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { gallerycell *cell = (gallerycell *)[collectionview dequeuereusablecellwithreuseidentifier:@"gallerycell" forindexpath:indexpath]; nsdictionary *photo = [self.beachimages objectatindex:indexpath.row]; [cell.imageview setimagewithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"%@", [photo objectforkey:@"original_url"]]] placeholderimage:[uiimage imagenamed:@"avatar-placeholder.png"]]; return cell; }
edit: maybe problem use autolayout ? here constraints: http://cl.ly/image/2l0m432w0u1v edit: tried adding constraint code:
[self.collectionview removeconstraints:self.collectionview.constraints]; nslayoutconstraint *con1 = [nslayoutconstraint constraintwithitem:self.collectionview attribute:nslayoutattributeheight relatedby:0 toitem:nil attribute:nslayoutattributenotanattribute multiplier:1 constant:320]; [self.collectionview addconstraints:@[con1]];
but not show cells...
Comments
Post a Comment