添加一个背景图像到UI集合视图

我是新的iOS开发,我想知道如何添加一个背景图像,将垂直重复我的UI集合视图,我已经创build显示图像数组?

 - (void)viewDidLoad { [super viewDidLoad]; self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.pnd"]]; } 

这将工作以及我认为比背景颜色的工作更正确。 直接去backgroundView

 - (void)viewDidLoad { [super viewDidLoad]; self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]]; } 

对于swift,添加到viewDidLoad():

  self.collectionView?.backgroundColor = UIColor(patternImage: UIImage(named: "background")!)