UIBezierPathを用いて線の描画をするプログラムを作成しましたが、線が描画されません。
原因はなんでしょうか?
画面は以下のようにviewは描画されているようです。
draw.swift
import UIKit class draw: UIView { override func drawRect(rect: CGRect) { let line = UIBezierPath(); // 起点 line.moveToPoint(CGPoint(x: 450, y: 60)); // 帰着点 line.addLineToPoint(CGPoint(x: 400, y: 300)); // ラインを結ぶ line.closePath() // 色の設定 UIColor.redColor() // ライン幅 line.lineWidth = 4 // 描画 line.stroke(); } }
ViewController.swift
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let screenWidth = self.view.bounds.width let screenHeight = self.view.bounds.height let testDraw = draw(frame: CGRect(x: 0, y: 0, width:screenWidth, height:screenHeight)) self.view.addSubview(testDraw) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/25 11:34