最终结果是在设备旋转后调整 cell.title 和 cell.description 的大小,使其填满整个屏幕。这个 Collection View Controller 位于 View Controller 内,因此我需要一个特定于单元格的解决方案。
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(collectionView == collection1)
{
SliderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"articleCellslider1"
forIndexPath:indexPath];
NSDictionary *item = [_articleListslider objectAtIndex:indexPath.item];
// set the article image
[cell.image setImageWithURL:[item objectForKey:@"image"]];
// set the text of title UILabel
cell.title.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"title"]];
cell.title.textColor = [UIColor colorWithRed:33.0f/255.0f green:74.0f/255.0f blue:146.0f/255.0f alpha:1.0f];
cell.title.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.5f];
// set the text of summary UILabel
cell.description.text = [NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n", [item objectForKey:@"description"]];
cell.description.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
cell.description.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.5f];
cell.targetURL = [item objectForKey:@"link"];
cell.sliderphoto = [item objectForKey:@"sliderphoto"];
cell.date.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"pubDate"]];
cell.category.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"category"]];
return cell;
[self performSegueWithIdentifier:@"Slider" sender:indexPath];
}
我想要在旋转时专门调整大小的单元格是 cell.title 和 cell.description
最佳答案
重写 UIviewController 的旋转委托(delegate)方法之一,尝试 willRotateToInterfaceOrientation (可能是 did 而不是 will 更好)然后当你捕获它时,重新加载你的 TableView 并设置一些标志来知道它已旋转。
然后实现UICollectionViewDelegateFlowLayout、collectionView:layout:sizeForItemAtIndexPath: (根据方向更改此处的大小)
关于ios - 如何在旋转时调整 CollectionView 的特定单元格的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992603/