的高度其實我要動態地設置按鈕和按鍵的標題出現動態我都試試這個,得到了動態內容的寬度,但不是在設置單元格的寬度和高度。一套動態的寬度和收集觀察室
- (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);
}
和輸出是這樣
這是完美的我想如果我讓細胞活力的寬度和高度,所以請指導我這個。
你想讓單元格寬度足夠大以顯示單元格文本嗎? –
或單元格+標籤高度以顯示全文? –
現全文細胞 – Virus