我試圖重新實現不定式滾動UICollectionView
看到here。那名失蹤我的事情:而不是UICollectionView顯示黑屏
ViewController.h:
@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
@end
DataCell.h:
@interface DataCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *label;
@end
DataCell.m:
#import "DataCell.h"
@implementation DataCell
-(instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if(self){
self.label = [[UILabel alloc] initWithFrame:self.bounds];
self.autoresizesSubviews = YES;
self.label.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
self.label.textAlignment = NSTextAlignmentCenter;
self.label.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.label];
}
return self;
}
@end
個CustomCollectionView.h:
@interface CustomCollectionView : UICollectionView
@end
對於我用故事板整個項目和正常UIViewController
。在這個視圖控制器上,我在Interface Builder中添加了一個UICollectionView
。我將集合視圖的出口與視圖控制器連接起來,並將數據源和委託方法再次設置到我的視圖控制器。我還在Interface Builder中設置了UICollectionViewCell
的自定義類和重用標識符。
所以一切都應該工作,但我只會得到一個黑屏。我錯過了什麼?您可以下載整個項目here。
如果您希望背景爲cl耳朵,你必須使用'collectionView.backgroundColor = [UIColor clearColor];''和'collectionView。backgroundView = [[UIView alloc] initWithFrame:CGRectZero];' – Multinerd 2016-12-01 21:11:59