In my porject I have uicolelctionview
and custom cell. In collectionView:CellForItemAtIndexPath
I get the custom cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionCell
and add this code
cell.personImage.layer.cornerRadius=(cell.bounds.size.height-10)/2
cell.personImage.layer.borderWidth=3
cell.personImage.layer.masksToBounds=true
I was hopping to get this type of view:
but some of cells appears like this:
and I have to reloatData to get current cell view. Still cant understand why I get this bug
The reason you see the images shaped "diamond like" is because cornerRadius
is set to a dynamic int at the moment, and it's set to something more then half of itself. The cornerRadius you should be using needs to be a lot less then (cell.bounds.size.height-10)/2
.
as Michael said, try using something like:
cell.personImage.layer.cornerRadius = testView.frame.width / 2
and see what your outcome is.
You can try to set dynamic corner radius with the following code:
cell.personImage.layer.cornerRadius = cell.personImage.frame.width / 2.0
Hope this helps :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.