Help us understand the problem. What is going on with this article?

[Swift3] UIImageViewにグリッド線を描画する

More than 3 years have passed since last update.

前提

要素 バージョン
xcode 8.2.1
Swift 3.0.2
iPhone 6s
iOS 10.2.1

概要

UIImageViewに以下の様な3×3(?)のグリッド線を描画する
IMG_1768.png

コード

UIViewをStoryBoardで画面いっぱいに貼り付けて、UiViewのカスタムクラスを作成する

class GridView: UIView {

  override func draw(_ rect: CGRect) {
    let path = UIBezierPath()
    path.lineWidth = 1.5

    UIColor.white.setStroke()
    path.move(   to: getPoint(rect, x: 1, y: 0))
    path.addLine(to: getPoint(rect, x: 1, y: 3))
    path.move(   to: getPoint(rect, x: 2, y: 0))
    path.addLine(to: getPoint(rect, x: 2, y: 3))
    path.move(   to: getPoint(rect, x: 0, y: 1))
    path.addLine(to: getPoint(rect, x: 3, y: 1))
    path.move(   to: getPoint(rect, x: 0, y: 2))
    path.addLine(to: getPoint(rect, x: 3, y: 2))
    path.stroke()
  }

  /* View上の指定した区画の座標を取得 */
  private func getPoint(_ rect: CGRect, x: CGFloat, y: CGFloat) -> CGPoint {
    let width = rect.width / 3.0
    let height = rect.height / 3.0
    return CGPoint(x: width * x, y: height * y)
  }

}
Sa2Knight
下の上ぐらいの伸び悩んでるWebプログラマ。色々な記事を読んで勉強しつつ、自ら学んだことを投稿して整理したりしているので誤った情報を発信してるかもしれません。お気づきの際はご指摘頂ければ幸いです。
https://github.com/Sa2Knight/Curriculum-Vitae
studist
「伝えることを、もっと簡単に」をミッションにビジュアルSOPマネジメントプラットフォームのBtoB SaaS「Teachme Biz」を開発・運営するスタートアップ
https://medium.com/studist-dev
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした