在 UICollectionView Xcode 中添加子视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20113298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:19:45  来源:igfitidea点击:

Adding subview inside UICollectionView Xcode

iosobjective-cxcodeuicollectionview

提问by user241641

I am Working in UICollectionViewadded my Device Photos inside UICollectionViewCell, now I want to create subview inside my UICollectionView. Please suggest to me how to add subviewinside UICollectionViews. Need any code or links.

我正在工作,在UICollectionView里面添加了我的设备照片UICollectionViewCell,现在我想在我的UICollectionView. 请建议我如何在subview里面添加UICollectionViews。需要任何代码或链接。

回答by Amar

Adding a subview is as simple as,

添加子视图非常简单,

//Create subview    
UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.collectionView.frame.size.width, 20)];
//Add
[collectionView addSubview:subview];
//Bring to front so that it does not get hidden by cells
[collectionView bringSubviewToFront:subview];
//This will shift collectionView content down by 20px at top
[collectionView setContentInset:UIEdgeInsetsMake(subview.frame.size.height, 0, 0, 0)];

The above code will add a subview at top of collectionView. Is this what you are looking for? If not please provide more details in your question.

上面的代码将在 collectionView 的顶部添加一个子视图。这是你想要的?如果不是,请在您的问题中提供更多详细信息。