That being said, if we are able to write a function to generalise the pattern of how boxes should be placed in the main view, we can achieve the same result in main view as a UICollectionView with a UICollectionViewLayout. Therefore, if we are to write a UICollectionViewFlowLayout class on our own, all we have to do is to generalise the pattern of how these boxes will be placed and write a function to produce these positional codes of our child views. So what is the catch? The catch is that UICollectionViewFlowLayout must contain a generic function that is capable of calculating the position of its child views (cells) correctly regardless how many these child views there are. Initialisation codes reside in cellForItem datasource method, while the position codes reside in UICollectionViewLayout class. The only difference is that, if we are to add a few more boxes to our main view, we need to manually write the codes for all the boxes added (Initialisation & position codes) while for UICollectionView, it will just automatically lay out the added boxes(or cells) in the same way but without the need of anymore Initialisation & position codes. If i am to ask you to add four boxes onto the main view of a view controller, so that they are arranged exactly as shown in Fig.1 belowīut now if you really think about the four boxes we have added to the main view, doesn’t the design, or the layout, resembles a lot of how UICollectionView will layout four cells of the same size if its UICollectionViewLayout is UICollectionViewFlowLayout? Unfolding The Magic In UICollectionViewFlowLayout 3.1 Adding Four Boxes But you should understand how to use them without me explaining much after this tutorial. There are other attributes in UICollectionViewLayoutAttributes besides frame. Whenever you set the frame property of the UICollectionViewLayoutAttributes, you are essentially setting the frame of the cell. But in UICollectionView world, we call the child views Cell and we set the views through a wrapper class called UICollectionViewLayoutAttributes. In essence, UICollectionViewLayout is just a class object that takes the responsibility of arranging the child views of a UICollectionView. CollectionView (Delegate and DataSource).You need to have at least a good understanding of the following subjects to understand the guide UICollectionViewLayout can be complicated but it Is definitely not difficult. But don’t let the world “complicated” scared you away. The reason for such an advice is simple: UICollectionViewLayout can be rather complicated. If you have just started to pick up iOS programming for not too long, I believe most of the people would advice you against understanding too much of UICollectionViewLayout because UICollectionViewFlowLayout will, under most circumstances, be sufficient for what you need. Step by Step Guide to UICollectionViewLayout showsHorizontalScrollIndicator = NO 注册cell forCellWithReuseIdentifier : ] 注册HeaderView forSupplementaryViewOfKind :UICollectionElementKindSectionHeader withReuseIdentifier : ] 注册FooterView forSupplementaryViewOfKind :UICollectionElementKindSectionFooter withReuseIdentifier : ] 刷新对应的列 [ self. showsVerticalScrollIndicator = NO 是否显示横向滚动条 self. sectionInset = UIEdgeInsetsMake ( 5, 5, 5, 5 ) 设置cell的头部高度 self. minimumInteritemSpacing = 10 设置cell的内间距 self. minimumLineSpacing = 100 设置cell的左右间距 self. scrollDirection = UICollectionViewScrollDirectionHorizontal 设置cell的大小 self. collectionView = collectionView UICollectionViewScrollDirectionVertical, 竖向排布 UICollectionViewScrollDirectionHorizontal 横向排布 self. height ) collectionViewLayout :flowLayout ] self. flowLayout = flowLayout collectionView实例化对象和大小 UICollectionView *collectionView = initWithFrame : CGRectMake ( 0, 0, self. 下面介绍一下collectionview的常用属性跟方法。‘ 初始化cell的样式 UICollectionViewFlowLayout *flowLayout = init ] self.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |