LoginSignup
0
1

More than 5 years have passed since last update.

パラメータひとつでサッとUIViewに枠線を引く

Last updated at Posted at 2017-10-01

あれ?タッチ反応しない?viewのサイズ合ってる?みたいな事態の時によく使ってます
さっとUIViewに赤い枠線を引いたり消したりするパラメータを追加するextension

使い方

let v = UIView(frame:CGRect(x:0, y:0, width:100, height:100))
v.isDrawRectangle = true //赤い枠線を引く
v.isDrawRectangle = false //赤い枠線を消す

ソース

extension UIView{
  var isDrawRectangle:Bool{
    get{
      return self.layer.borderWidth > 0
    }
    set(value){
      if(value){
        self.layer.borderColor = UIColor.red.cgColor
        self.layer.borderWidth = 1
      }
      else{
        self.layer.borderColor = UIColor.clear.cgColor
        self.layer.borderWidth = 0
      }
    }
  }
}
0
1
2

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
0
1