2017-12-11 3 views

答えて

0

Interface Builderのウィンドウの属性インスペクタで、「透明タイトルバー」と「フルサイズのコンテンツビュー」オプションをオンにします。次に、ウィンドウのコンテンツビューの上部に赤いビューを置くと、タイトルバーの後ろに表示されます。

は、ビューのために、私はこのでした:

class RedView: NSView { 
    // draw is simple; just fill the rect with red 
    override func draw(_ dirtyRect: NSRect) { 
     NSColor.red.set() // maybe experiment to find a better-looking shade of red 
     dirtyRect.fill() 
    } 

    // provide an intrinsic content size, to make our view prefer to be the same height 
    // as the title bar. 
    override var intrinsicContentSize: NSSize { 
     guard let window = self.window, let contentView = window.contentView else { 
      return super.intrinsicContentSize 
     } 

     // contentView.frame is the entire frame, contentLayoutRect is the part not 
     // overlapping the title bar. The difference will therefore be the height 
     // of the title bar. 
     let height = NSHeight(contentView.frame) - NSHeight(window.contentLayoutRect) 

     // I just return noIntrinsicMetric for the width since the edge constraints we set 
     // up in IB will override whatever we put here anyway 
     return NSSize(width: NSView.noIntrinsicMetric, height: height) 
    } 
} 

をし、このようにそれを配置し:これらのウィンドウ設定で

enter image description here

enter image description here

結果この中:

enter image description here

注意してください。大きな力で大きな責任を負っています。赤 - 緑色の色盲を持つ人々のためにインターフェイスを使いにくくしないように注意してください。上記の画像を見ると、おそらくNSColor.redよりも明るい赤色の色調で表示されています。なぜなら、その暗さによってタイトルがわかりにくくなるからです。しかし、あなたは良いものが得られるまでそれを試すことができます。

+0

私はストーリーボードを使用していませんが、XIBです。透明タイトルバーを取得できません。外観セクションには存在しません。してください –

+0

もう一度dirtyRect.fill()がエラーを表示しています –

+0

@ RaghunathSahoo XIBまたはストーリーボードのいずれかでウィンドウを選択すると、オプションが表示されます。 Xcode 9またはそれ以前のバージョンを使用していますか? –

関連する問題