2015-01-27 64 views
0

我是新使用UICollectionView,因为我一直在使用UITableView,所以我事先道歉。UICollectionView单元对齐屏幕?

不管怎样,我有一些简单的代码,但由于某些原因,我还不熟悉,一些单元格被放置在屏幕之外而不是被移动到下一个级别。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    array = [ [NSMutableArray alloc] initWithObjects:@"Apple", @"Is", @"The", @"Bomb", @".com", @":D", nil]; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 5.0; 
} 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return 1; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return array.count; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 

    UILabel *label = (UILabel *)[cell viewWithTag:100]; 

    label.text = [array objectAtIndex:indexPath.row]; 

    [cell.layer setBorderWidth:2.0f]; 
    [cell.layer setBorderColor:[UIColor whiteColor].CGColor]; 

    [cell.layer setCornerRadius:10.f]; 

    return cell; 
} 

​​

发生了什么事与 “炸弹” 和 “.COM” 的细胞?为什么它切断屏幕?

+0

你的收藏视图的框架是什么?你是怎么设定的? – rdelmar 2015-01-27 00:11:16

回答

1

您需要在集合视图上设置视图约束。查看Autolayout编程为UICollectionView设置约束。

+0

我怎么知道如何设置UITableView的约束但不是UICollectionView,我不知道。真是个傻瓜! :) – Pangu 2015-01-27 02:14:36