2016-01-22 34 views

回答

3

显然没有任何办法的SPLITVIEW添加到工具栏本身,我怀疑我们在里德看到的是不是一个标准工具栏。在anycase获得这个,我做了以下

  1. 隐藏标题栏,透明工具栏和全屏视图上主控制器

Add to MainWindowController ViewDidLoad

  • 添加自定义视图高度为38到你的每个“sourcelist(边栏),contentlist(索引列表)和你的SplitViewController splitView项目的默认区域的最顶部。然后将按钮添加到此splitView
  • Do the same for the others

  • 这是它应该是什么样子的主要窗口上
  • MainWindow View Resized

  • 如果你想获得完整的工具栏外观。创建出口到所有customView与37点的高度(您向其中添加的那些按钮)和自定义背景,添加一个渐变和底部边框 enter image description here enter image description here
  • 0

    它是所有关于约束

    如果工具栏是在SPLITVIEW:

    工具栏上的约束集 “间距最近的邻居”,例如0左, right 然后按钮也必须有一个“与最近邻居的间距”,例如右边的8位

    编辑:看到这里按钮添加约束http://oi63.tinypic.com/2s7szgi.jpg

    +0

    对不起,我不明白你的意思。你谈过哪个按钮?我想知道的是如何使分割控件与分割视图的分割器一起移动。他们似乎正确对齐。我不知道他们是否可以彼此添加任何约束。非常感谢你。如果你能给我更多的帮助,将不胜感激。 – morphinewan

    +0

    在底部,您可以为每个选定对象设置约束条件 http://oi63.tinypic.com/2s7szgi.jpg – phimage

    +0

    1.工具栏中的控制器不能添加任何约束。 2. SplitView下面和工具栏甚至不属于相同的父视图。我如何向他们添加约束? – morphinewan

    1

    我已经适应livingstonef的实现对于Swift 3还添加了缺失的NSBezierPath扩展名:

    import Cocoa 
    
    @IBDesignable class ToolbarCustomView: NSView { 
    
        override func draw(_ dirtyRect: NSRect) { 
         super.draw(dirtyRect) 
    
         //The background 
         let startingColor = NSColor(red: 232/256, green: 230/256, blue: 232/256, alpha: 1) 
         let endingColor = NSColor(red: 209/256, green: 208/256, blue: 209/256, alpha: 1) 
         let gradient = NSGradient(starting: startingColor, ending: endingColor) 
    
         gradient?.draw(in: self.bounds, angle: 270) 
    
         //The bottom border 
         let borderPath = NSBezierPath() 
         let startingPoint = NSPoint(x: dirtyRect.origin.x, y: 0) 
         let stoppingPoint = NSPoint(x: dirtyRect.width, y: 0) 
    
         borderPath.move(to: startingPoint) 
         borderPath.line(to: stoppingPoint) 
    
         let shapeLayer = CAShapeLayer() 
    
         self.layer?.addSublayer(shapeLayer) 
    
         shapeLayer.path = borderPath.cgPath 
         shapeLayer.strokeColor = NSColor(red: 180/256, green: 182/256, blue: 180/256, alpha: 0.6).cgColor 
         shapeLayer.fillColor = .clear 
         shapeLayer.lineWidth = 1 
        } 
    } 
    
    extension NSBezierPath { 
    
        public var cgPath: CGPath { 
         let path = CGMutablePath() 
         var points = [CGPoint](repeating: .zero, count: 3) 
    
         for i in 0 ..< self.elementCount { 
          let type = self.element(at: i, associatedPoints: &points) 
          switch type { 
          case .moveToBezierPathElement: 
           path.move(to: points[0]) 
          case .lineToBezierPathElement: 
           path.addLine(to: points[0]) 
          case .curveToBezierPathElement: 
           path.addCurve(to: points[2], control1: points[0], control2: points[1]) 
          case .closePathBezierPathElement: 
           path.closeSubpath() 
          } 
         } 
    
         return path 
        } 
    } 
    
    +1

    实际上,您甚至不需要Bezier在工具栏上设置边框,只需向图层添加边框即可。当窗口不再是关键窗口时,也可能需要更改工具栏的渐变。这是一个更新的自定义工具栏,在Swift 3.0中工作https://gist.github.com/livingstonef/04bc9344a501cf198db13d1e48a6addd – stone

    +0

    感谢您的更新,关键窗口逻辑工作正常。除非将边框宽度设置为1,否则我不会获得图层边框。但是,边框位于视图的所有边上,而不仅仅位于底部。我错过了什么吗? – Felix

    相关问题