LoginSignup
18
16

More than 5 years have passed since last update.

SwiftでUIViewの下に線を引きたい

Posted at

やりたいこと

  • 対象はUICollectionViewCell
  • やんごとなき事情からcollectionViewのセル同士のマージンはゼロ
  • collectionViewの中に一部だけtableViewみたいな並びになるところがある
  • セル同士のマージンがゼロなので境界がわからない、くっついて見えちゃう

やること

    let bottomBorder = CALayer()
    let borderWidth = CGFloat(0.4) // <- 線の太さ
    bottomBorder.frame = CGRectMake(0, self.frame.size.height - borderWidth, self.frame.size.width, borderWidth)
    bottomBorder.backgroundColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1).CGColor // <- 線の色
    self.layer.addSublayer(bottomBorder)

結果

やんごとなき事情からスクショはなし。

線は引けました。

所感

セル同士くっついて見えて境界がわからない!→じゃセルに線を引こう!ってのは間違ってる気がします
一旦見た目優先で作ってあとで綺麗にしよう。。。

18
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16