自分は手元では問題無くImageView
が丸くなりました。
swift
1import UIKit
2
3class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
4
5 @IBOutlet weak var collectionView: UICollectionView!
6
7 override func viewDidLoad() {
8 super.viewDidLoad()
9
10 }
11
12 // MARK: - UICollectionViewDelegate
13 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
14 let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
15 cell.backgroundColor = UIColor.yellowColor()
16 return cell
17 }
18
19 func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
20 return 1
21 }
22
23 func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
24 return 30;
25 }
26
27 // Cell Size Change
28 func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
29 let size = UIScreen.mainScreen().bounds.size.width / 2 - 10
30 return CGSizeMake(size, size)
31 }
32
33 override func didReceiveMemoryWarning() {
34 super.didReceiveMemoryWarning()
35 }
36}
37
38// Custom Cell Class
39import UIKit
40
41class CustomCell: UICollectionViewCell {
42
43 @IBOutlet weak var imageView: UIImageView!
44
45 override func awakeFromNib() {
46 super.awakeFromNib()
47 setimageView()
48 }
49
50 func setimageView() {
51 imageView.layer.cornerRadius = imageView.frame.height / 2
52 imageView.layer.masksToBounds = true
53 }
54}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/19 05:47