簡體   English   中英

如何在旋轉時為CollectionView調整特定單元格的大小?

[英]How do I resize a specific cell for CollectionView on rotation?

最終結果是,旋轉設備后,將改變cell.title和cell.description的大小,以使其充滿整個屏幕。 這個collectionviewcontroller在Viewcontroller中,因此我需要一個特定於單元格的解決方案。

- (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委托方法之一,請嘗試willRotateToInterfaceOrientation(可能會做,而不是將要更好),然后在捕獲它時,重新加載表視圖並設置一些標志以知道它是旋轉的。

然后實現UICollectionViewDelegateFlowLayout,collectionView:layout:sizeForItemAtIndexPath:(根據方向在此處更改大小)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM