Xcode 如何使NSToolbar中的控制器与NSSplitViewController'一起移动;s视图,如Reeder或Mail.app
我正在开发一个cocoa应用程序。它包含一个具有一些功能按钮的工具栏。就像里德一样 我想在调整拆分视图的大小时调整工具栏部分的大小。有些东西的工作原理如下。如何实现这种特性 任何人可以帮助我或给一些建议将不胜感激 我正在使用XCode7、Swift和故事板进行开发Xcode 如何使NSToolbar中的控制器与NSSplitViewController'一起移动;s视图,如Reeder或Mail.app,xcode,cocoa,autolayout,nssplitview,nstoolbar,Xcode,Cocoa,Autolayout,Nssplitview,Nstoolbar,我正在开发一个cocoa应用程序。它包含一个具有一些功能按钮的工具栏。就像里德一样 我想在调整拆分视图的大小时调整工具栏部分的大小。有些东西的工作原理如下。如何实现这种特性 任何人可以帮助我或给一些建议将不胜感激 我正在使用XCode7、Swift和故事板进行开发 这都是关于约束的 如果工具栏在splitview中: 在工具栏上设置“到最近邻居的间距”约束,例如0表示左侧和右侧 然后按钮必须在工具栏上有一个“到最近邻居的间距”,例如右边的8 编辑:请参见此处的按钮以添加约束这都是关于约束的 如
这都是关于约束的 如果工具栏在splitview中: 在工具栏上设置“到最近邻居的间距”约束,例如0表示左侧和右侧 然后按钮必须在工具栏上有一个“到最近邻居的间距”,例如右边的8
编辑:请参见此处的按钮以添加约束这都是关于约束的 如果工具栏在splitview中: 在工具栏上设置“到最近邻居的间距”约束,例如0表示左侧和右侧 然后按钮必须在工具栏上有一个“到最近邻居的间距”,例如右边的8
编辑:查看此处的按钮以添加约束显然,没有任何方法可以将splitView添加到工具栏本身,我怀疑我们在reeder中看到的不是标准工具栏。无论如何,为了得到这个,我做了以下几件事
显然,没有任何方法向工具栏本身添加splitView,我怀疑我们在reeder中看到的不是标准工具栏
我已将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
}
}
导入可可粉
@IBDesignable类工具栏自定义视图:NSView{
重写函数绘图(uTyrect:NSRect){
超级绘图(直接绘图)
//背景
让startingColor=NSColor(红色:232/256,绿色:230/256,蓝色:232/256,alpha:1)
设endingColor=NSColor(红色:209/256,绿色:208/256,蓝色:209/256,alpha:1)
let gradient=NSGradient(开始:开始颜色,结束:结束颜色)
渐变?绘制(in:自边界,角度:270)
//底边
让borderPath=NSBezierPath()
让startingPoint=NSPoint(x:dirtyRect.origin.x,y:0)
让停止点=n点(x:dirtyRect.width,y:0)
移动(到:起始点)
borderPath.line(到:停止点)
设shapeLayer=CAShapeLayer()
self.layer?.addSublayer(shapeLayer)
shapeLayer.path=borderPath.cgPath
shapeLayer.strokeColor=NSColor(红色:180/256,绿色:182/256,蓝色:180/256,alpha:0.6)。cgColor
shapeLayer.fillColor=.clear
shapeLayer.lineWidth=1
}
}
扩展NSBezierPath{
公共变量cgPath:cgPath{
let path=CGMutablePath()
变量点=[CGPoint](重复:.0,计数:3)
对于0中的i..
我已将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
}
}
导入可可粉
@IBDesignable类工具栏自定义视图:NSView{
重写函数绘图(uTyrect:NSRect){
超级绘图(直接绘图)
//背景
让startingColor=NSColor(红色:232/256,绿色:230/256,蓝色:232/256,alpha:1)
设endingColor=NSColor(红色:209/256,绿色:208/256,蓝色:209/256,alpha:1)
let gradient=NSGradient(开始:开始颜色,结束:结束颜色)
渐变?绘制(in:自边界,角度:270)
//底边
让borderPath=NSBezierPath()
让startingPoint=NSPoint(x:dirtyRect.origin.x,y:0)
让停止点=n点(x:dirtyRect.width,y:0)
移动(到:起始点)
borderPath.line(到:停止点)
设shapeLayer=CAShapeLayer()
self.layer?.addSublayer(shapeLayer)
shapeLayer.path=borderPath.cgPath
shapeLayer.strokeColor=NSColor(红色:180/256,绿色:182/256,蓝色:180/256,alpha:0.6)。cgColor
shapeLayer.fillColor=.clear
shapeLayer.lineWidth=1
}
}
扩展NSBezierPath{
公共变量cgPath:cgPath{
let path=CGMutablePath()
变量点=[CGP