I have nothing to do. I did aUICollectionViewThe circular layout, renderings below

The controller code is as follows

// // viewController.m // CollectionViewTest // // Created by Huang Ruion 2017/5/24. // Copyright © 2017 CoderHuang. All rights reserved. // #import "ViewController.h" #import "MyLayout.h" #import "MyCollectionView.h" @interface ViewController () <UICollectionViewDelegate, UICollectionViewDataSource> { NSInteger count; } @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (weak, nonatomic) IBOutlet UISlider *countSlider; @property (weak, nonatomic) IBOutlet UISlider *originSlider; Label @property (weak, nonatomic) IBOutlet UILabel *countLabel; @property (nonatomic, strong) NSArray <UIColor *> *colors; @end @implementation ViewController #pragma mark - View did load - (void)viewDidLoad { [super viewDidLoad]; count = (NSInteger)self.countSlider.value; self.countLabel.text = [NSString stringWithFormat:@"%ld", (long)count]; self.colors = @[ [UIColor redColor], [UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor blueColor], [UIColor magentaColor], [UIColor purpleColor], ]; } #pragma mark - Slider click - (IBAction)valueChange:(UISlider *)sender { if (sender == self.countSlider) { NSInteger nCount = (NSInteger)self.countSlider.value; if (nCount ! = count) { count = nCount; self.countLabel.text = [NSString stringWithFormat:@"%ld", (long)count]; [self.collectionView reloadData]; } } else { MyLayout *layout = (MyLayout *)self.collectionView.collectionViewLayout; layout.origin = sender.value; [self.collectionView reloadData]; }} // Similar to UITableView, UICollectionView is also a #pragma mark-delegate with sections and rows (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView CellForItemAtIndexPath :(NSIndexPath *)indexPath {// ReuseIdentifier UICollectionViewCell *cell = has been set in StoryBoard [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.backgroundColor = self.colors[indexPath.row % self.colors.count]; return cell; } @endCopy the code

# StoryBoard is shown in figure

Note that to change the Layout of the CollectionView to Custom and then select the Custom class MyLayout, it must inherit from the UICollectionViewLayout class.

#MyLayout.h

// // mylayout. h // CollectionViewTest // // Created by Huang Rui on 2017/5/24. // Copyright © 2017 CoderHuang. All Rights reserved. // #import <UIKit/UIKit.h> @interface MyLayout : UICollectionViewLayout @property (nonatomic, assign) CGFloat Origin; @endCopy the code

#MyLayout.m

// // mylayout. m // CollectionViewTest // // Created by Huang Rui on 2017/5/24. // Copyright © 2017 CoderHuang. All Rights // #import "myLayout.h" @interface MyLayout () {// Number of items NSInteger count; // CGPoint Center with circular layout; // Radius of the circular layout CGFloat radius; } @end@implementation MyLayout - (void)prepareLayout {count = [self.collectionView numberOfItemsInSection:0]; center = CGPointMake(self.collectionView.frame.size.width / 2, self.collectionView.frame.size.height / 2); radius = 150; } / / return ContentSize - (CGSize) collectionViewContentSize {return self. CollectionView. Frame. The size; } / / for each Item has a UICollectionViewLayoutAttributes objects and its corresponding, this object contains only the layout of the Item information. - (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray *arr = [NSMutableArray array]; for (NSInteger i = 0; i < count; i++) { [arr addObject:[self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]]; } return arr; } / / to create the layout of the Item attributes object according to indexPath - layoutAttributesForItemAtIndexPath: (NSIndexPath UICollectionViewLayoutAttributes (*)  *)indexPath { NSLog(@"%s", __func__); UICollectionViewLayoutAttributes *attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; CGFloat angle = 2 * M_PI / count * indexPath.row + M_PI_2 * self.origin; CGFloat x = center.x + cos(angle) * radius; CGFloat y = center.y - sin(angle) * radius; attr.center = CGPointMake(x, y); attr.size = CGSizeMake(30, 30); return attr; } @endCopy the code