2012-12-08 42 views

回答

2

截至Apples WWDC Video有關UICollectionViews您應該創建一個自定義UICollectionViewFlowLayout。 如上所述,您應該設置CollectionView的底部和頂部Edge Insets,以便只有一個Cell適合其中,其餘部分將由CollectionView完成。

邊緣插圖可以UIEdgeInsetsMake(top, left, bottom, right)

可以這樣做,在你的佈局可以自定義init這樣的:

-(id)init 
{ 
    self = [super init]; 
    if (self) { 
     self.itemSize = CGSizeMake(100, 100); 
     self.scrollDirection = UICollectionViewScrollDirectionHorizontal; 

     CGRect bounds = [[UIScreen mainScreen] bounds]; 
     CGFloat spacing = bounds.size.height/2 - self.itemSize.height/2; 
     self.sectionInset = UIEdgeInsetsMake(spacing, 0, spacing, 0); 
    } 
    return self; 
} 

所以,其實你做的CollectionView的高度高度屏幕減去一個單元格的高度,除了它居中。

希望有所幫助。

0

如果想要一個項目爲什麼客人不願意嘗試的UITableView

UITableView *myTableView = [UITableView alloc] init]; 

代表

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
相關問題