If self.superview
is nil, then at the time addWhiteLine
is being called, self hasn't been added to the view hierarchy yet. This actually makes sense given that you're calling it from the initWithCoder
. Whoever's loading this view has to alloc
/init
before adding it to a superview. As a fix, why add to self.superview
, shouldn't you add to self
instead?
Edit: As discussed in comments, another problem is that the line is being drawn outside the frame, so it should be self.frame.origin.y + self.frame.size.height-borderWidth
instead.