Firstly we need to calculate text length and configure to collection view cell size layout.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGSize calCulateSize =[(NSString*)[_categoryList objectAtIndex:indexPath.row] sizeWithAttributes:NULL];
calCulateSize.width = calCulateSize.width+50; // for better look we add more 50 pixel
calCulateSize.height = 50; // fixed height
return calCulateSize;
}
as usual, we implement all of the required collection view delegate and data source, then we see look like collection view cell. demo attached here, if any things need, let me know.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8Qd7YNolQef5Z_2QGEaA2EanUSKtGDjgR8MOf_zHSk1GpWOdlfRgf3VDzhqBgYd0HbwEQYoZQPip8wANbIoRSrgPoUXttOY1qpFUhyphenhyphen5C68mq5yhOzPldWMtnKjlsOrW2SNy3qAS_9z4E/s400/dynamicCollectionView.png)
Demo here
No comments:
Post a Comment