Eigentlich möchte ich Button dynamisch und Titel der Schaltfläche erscheinen Dynamic Ich habe dies versucht und bekam Breite von Dynamic Inhalt, aber nicht Einstellung der Breite und Höhe der Zelle.set Dynamische Breite und Höhe der Kollektion view cell
- (void)viewDidLoad {
[super viewDidLoad];
ContentArray = [[NSMutableArray alloc]init];
self.collectionview.delegate = self;
self.collectionview.dataSource =self;
self.collectionview.backgroundColor = [UIColor clearColor];
[ContentArray addObject:@"Planning"];
[ContentArray addObject:@"Resources"];
[ContentArray addObject:@"Human Resources"];
[ContentArray addObject:@"Agriculture"];
[ContentArray addObject:@"Resources management"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return ContentArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell"forIndexPath:indexPath];
[Cell.button setTitle:[ContentArray objectAtIndex:indexPath.row] forState:UIControlStateNormal];
return Cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGRect rect = [[ContentArray objectAtIndex:indexPath.row ] boundingRectWithSize:CGSizeMake(HUGE_VALF, 50) options:NSStringDrawingUsesFontLeading attributes:nil context:nil] ;
return CGSizeMake(rect.size.width, 50);
}
und Ausgang ist wie dieser
Dieses ist perfekt Ich denke, wenn ich Zelle dynamische Breite und Höhe machen, also bitte mich durch diese führen.
Möchten Sie die Zellenbreite groß genug machen, um den Zellentext anzuzeigen? –
oder Zelle + Label Höhe, um den vollständigen Text anzuzeigen? –
SHOW FULL TEXT IN CELL – Virus