我有一个NSStackView,内容在运行时添加,我希望内容超过一定的高度能出现滚动条,因此在外面套了一个NSScrollView。
现在已经可以出现滚动条了,但是有新的问题,NSStackView新增的内容是从下往上新增。
请问,新增的内容如何从上往下。
下面是我的main.storyboard
下面是viewController代码
import Cocoa
class ViewController: NSViewController {
var todoList:[Todo] = []
@IBOutlet weak var todosStackView: NSStackView!
@IBOutlet weak var todosScrollView: NSScrollView!
@IBAction func onEnter(sender: NSTextField) {
//创建Todo
let todo = Todo()
todo.content = sender.stringValue
self.todoList.append(todo)
//根据上面的Todo创建一个checkbox
let todoItemView = TodoItem()
todoItemView.setButtonType(.SwitchButton)
todoItemView.todo=todo
//将上面的checkbox加入NSStackView
todosStackView.addView(todoItemView, inGravity: .Top)
}
@IBOutlet var todos: NSArrayController!
override func viewDidLoad() {
super.viewDidLoad()
todosScrollView.hasVerticalScroller = true
todosScrollView.hasHorizontalScroller = true
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
下面是checkbox的代码
import Cocoa
class TodoItem: NSButton {
var todo:Todo!{
didSet {
self.title = self.todo.content
self.state = self.todo.done ? NSOnState : NSOffState
}
}
func completeTodo(){
if(self.state == NSOnState){
self.todo.done = true
}else{
self.todo.done = false
}
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
self.setButtonType(.SwitchButton)
self.target = self
self.action = #selector(self.completeTodo)
}
}
I asked this question on stackoverflow and it solved my problem.
NSClipView is a subclass of NSView. The default coordinate of NSView is the lower left corner.
So just change isFlipped to true, which means flipping the coordinates from the lower left corner to the upper left corner.
Then change the custom class of ClipView to FlippedClipView in main.storyboard
Original answer
Hello, I am a novice using spring security. I searched your previous question about customizing UserPasswordAthenticationFilter on the Internet. I also encountered the same problem and wanted to write my own authentication. Have you solved it now?