# Lines not appereing when calling subclass

**URL:** <https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163>\
**Category:** Swift\
**Created:** [August 23, 2020, 1:03am UTC](https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163 "2020-08-23T01:03:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [August 23, 2020, 1:03am UTC](https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163/1 "2020-08-23T01:03:36Z")

</div>

My code below should draw a x and y line just a graph plaine but no line are appearing. I just dont know why they are not appearing.

> import UIKit
> 
> class ViewController: UIViewController{  
> var box = Line()  
> override func viewDidLoad() {  
> super.viewDidLoad()  
> view.addSubview(box)  
> box.drawLine()
> 
> ```
> }
> 
> ```
> 
> }
> 
> class Line:UIView {
> 
> ```
> var line = UIBezierPath()
> var line2 = UIBezierPath()
> 
> func drawLine() {
> line.move(to: CGPoint(x: 0, y: bounds.height / 2))
> line.addLine(to: CGPoint(x: (bounds.width) , y: bounds.height / 2))
> UIColor.black.setStroke()
> line.lineWidth = 0.1
> line.stroke()
>     
> line2.move(to: CGPoint(x: bounds.width / 2, y:0 ))
> line2.addLine(to: CGPoint(x: (bounds.width / 2) , y: (bounds.height) ))
>     
>     
>     
> UIColor.black.setStroke()
> line2.lineWidth = 0.1
> line2.stroke()
>     
>     
>     
> }
> 
> override func draw(_ rect: CGRect) {
> drawLine()
> }
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![lganti](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/lganti/32/103565_2.png) [@lganti](https://forums.kodeco.com/u/lganti)\
**Post date:** [August 29, 2020, 7:07am UTC](https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163/2 "2020-08-29T07:07:33Z")

</div>

check the frame of the line in the view debugger / set the frame of the line

` box.frame = CGRect(x: 150, y: 200, width: 200, height: 20)`

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [September 12, 2020, 9:47am UTC](https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163/3 "2020-09-12T09:47:18Z")

</div>

in your code for viewDidLoad, you need to set a frame for box after the view.addSubView(box)

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [February 5, 2021, 5:15pm UTC](https://forums.kodeco.com/t/lines-not-appereing-when-calling-subclass/118163/4 "2021-02-05T17:15:52Z")

</div>

Closed on February 5, 2021, 5:15pm UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
