2017-07-06 19 views
0

下の図のように中央のセルが強調表示されるUICollectionViewがあります。UICollectionViewが影付きのセルを強調表示しました

enter image description here

私は、中心セルの周りに影を作るために、次のコードを使用しています。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell : STSuggestStyleCell = collectionView.dequeueReusableCell(for: indexPath) 

    if indexPath.row == 4{ 

     cell.imageProfile.layer.cornerRadius = 2.0 
     cell.imageProfile.layer.borderWidth = 1.0; 
     cell.imageProfile.layer.borderColor = UIColor.clear.cgColor 
     cell.imageProfile.layer.masksToBounds = true; 

     cell.imageProfile.layer.shadowColor = UIColor.lightGray.cgColor; 
     cell.imageProfile.layer.shadowOffset = CGSize(width: 2.0, height: 2.0); 
     cell.imageProfile.layer.shadowRadius = 2.0; 
     cell.imageProfile.layer.shadowOpacity = 2.0; 
     cell.imageProfile.layer.masksToBounds = false; 
     cell.imageProfile.layer.shadowPath = UIBezierPath(roundedRect: cell.imageProfile.bounds, cornerRadius: cell.imageProfile.layer.cornerRadius).cgPath 

        cell.imageProfile.backgroundColor = UIColor.white 


    } 

    return cell 
} 

しかし、正しく動作しません。

誰でもUICollectionViewを使用して上記のデザインを達成する方法を教えてもらえますか?

答えて

0

センター内のセルのレッドラインを見

enter image description here

セル自体は影の効果を持っていません。影は隣のセルにあります。したがって、ここで行う必要があるのは、セルに他のセルの「オーバーレイ」を求めることです。

cell.clipToBounds = trueに電話すると、中央のセルを隣接セルにオーバーレイすることができます。次に、シャドウエフェクトを中央のセルから使い切ってください。

+0

私は既に上記の解決策を試しています。それは動作していません。 –

+0

@ Aman.Sanghaniあなたは影を見ることができますか?または細胞の内側の影? –

+0

はいそれは働いた。ありがとうございました:) –

0

おそらく2つの異なるセルを作成する必要があります。その再利用機能のためです。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    if indexPath.row == 4{ 
     let cell : STSuggestStyleCell = collectionView.dequeueReusableCell(for: indexPath) 
     cell.imageProfile.layer.cornerRadius = 2.0 
     cell.imageProfile.layer.borderWidth = 1.0; 
     cell.imageProfile.layer.borderColor = UIColor.clear.cgColor 
     cell.imageProfile.layer.masksToBounds = true; 

     cell.imageProfile.layer.shadowColor = UIColor.lightGray.cgColor; 
     cell.imageProfile.layer.shadowOffset = CGSize(width: 2.0, height: 2.0); 
     cell.imageProfile.layer.shadowRadius = 2.0; 
     cell.imageProfile.layer.shadowOpacity = 2.0; 
     cell.imageProfile.layer.masksToBounds = false; 
     cell.imageProfile.layer.shadowPath = UIBezierPath(roundedRect: cell.imageProfile.bounds, cornerRadius: cell.imageProfile.layer.cornerRadius).cgPath 

     cell.imageProfile.backgroundColor = UIColor.white 
     return cell 
    }else{ 
     let cell : STSuggestNomalCell = collectionView.dequeueReusableCell(for: indexPath) 
     return cell 
    } 
} 
関連する問題