Interface Builder に入れようとするUICollectionCell
とUICollectionView
、原因不明で入れられません。セルは追加せずにツールバーに移動しますUICollectionView
私は使っている:
- iOS SDK 6.0
- X コード 4.5.1
- ストーリーボードを使用しない
Interface Builder に入れようとするUICollectionCell
とUICollectionView
、原因不明で入れられません。セルは追加せずにツールバーに移動しますUICollectionView
私は使っている:
StoryBoard 内の UICollectionView のみが UICollectionViewCell を内部に持っています。XIB を使用する場合は、CellName.xib で新しい XIB を作成し、それに CollectionViewCell を追加し、UICollectionView カスタム クラスの名前を指定します。その後、registerNib を使用します。
サンプルコード: https://github.com/lequysang/TestCollectionViewWithXIB
ファイルを使用している場合はUICollectionViewCell
、直接入れることはできません。ストーリーボードでのみ可能です。aを別の Xib ファイルに追加します。あなたのクラス名を付けてください。次に、コレクション ビューが表示される前にクラスまたは xib を登録します。UiCollectionView
Xib
UICollectionViewCell
[self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:CELL_ID];
通常、これは で行われviewDidLoad
ます。
UICollectionViewCell
これは使用せずにカスタムの実装ですXib
@implementation CollectionViewCell
@synthesize imageView = _imageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowRadius = 5.0f;
self.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
self.layer.shadowOpacity = 0.5f;
// Selected background view
UIView *backgroundView = [[UIView alloc]initWithFrame:self.bounds];
backgroundView.layer.borderColor = [[UIColor colorWithRed:0.529 green:0.808 blue:0.922 alpha:1]CGColor];
backgroundView.layer.borderWidth = 10.0f;
self.selectedBackgroundView = backgroundView;
// set content view
CGRect frame = CGRectMake(self.bounds.origin.x+5, self.bounds.origin.y+5, self.bounds.size.width-10, self.bounds.size.height-10);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageView = imageView;
[imageView release];
self.imageView.contentMode = UIViewContentModeScaleAspectFill ;
self.imageView.clipsToBounds = YES;
[self.contentView addSubview:self.imageView];
}
return self;
}