u16suzuの blog

日々学んだことのメモブログです。

cssのパディングとマージン

パディングとマージンどっちがどっちかよく忘れるのでメモしておく。

f:id:u16s:20160216182202p:plain

コード

<html>
<head>
<style type="text/css">
div  {
  padding : 10px; /* 要素とボーダーラインのあいだの距離 */
  border : 5px solid maroon; /* ボーダーラインの幅 */
  margin : 10px; /* ボーダーラインと画面の端の距離 */
  background-color : lightgreen;
}
</style>
</head>
<body>
  <div class="hoge">
    hoge
  </div>
</body>
</html>

ちなみにcssでは // をコメントに使えないので /* */ を使う必要がある。

Swiftでクラスからインスタンスを生成する

インスタンス化するクラスを定義

class Hoge {
    required init(){
    }
    
    class func newInstance()->Hoge {
        return Hoge.init()
    }
}

呼び出し

let hogeClass: Hoge.Type = Hoge.self
let hogeObject = hogeClass.init()

Rubyで行列とベクトルの演算

固有ベクトルは任意の行列m を適用した際に,向きが変わらないベクトルのこと

require 'matrix'

m = Matrix[
  [2,1],
  [1,2]
]

v1 = Vector[1, 1]
v2 = Vector[1, -1]

# v1は m の eigen vecotr
p m * v1 # => Vector[3, 3]

# v2 is eigen vector of matrix m too.
# eigen value is 1
p m * v2 # => Vector[1, -1]

参考

UIWebView でリンクをクリックしたとき safari で開く

UIWebView でリンクをクリックしたとき safari で開く

func webView(webView: UIWebView,
  shouldStartLoadWithRequest request: NSURLRequest,
  navigationType: UIWebViewNavigationType) -> Bool {

    if(navigationType == UIWebViewNavigationType.LinkClicked){
        UIApplication.sharedApplication().openURL(request.URL!)
        return false
    }

    return true
}

UIView の bounds と frame プロパティについて

サイズはどちらも同じで座標系が異なる

  • bounds : 座標系が自分のビュー基準
  • frame : 座標系が親ビュー基準

あとで読む