nstextfield

SWIFT: Nstextfield allow only specified characters

我是研究僧i 提交于 2021-02-19 01:56:04
问题 I need somebody to show me how to allow specific characters in a nstexfield in swift. For example when a user tries to enter a character which is not in the list the nstexfield will not show that character in the field.. Very simple. There are many IOS examples out there but could not find an OSX example. 回答1: First add a NSTextFieldDelegate to your class... and then add this : override func controlTextDidChange(obj: NSNotification) { let characterSet: NSCharacterSet = NSCharacterSet

Select all text in a NSTextField using Swift

半世苍凉 提交于 2021-02-07 09:17:57
问题 How can I programatically select all the text in a NSTextField using Swift? For UITextField theres a method like textField.selectedTextRange = textField.textRangeFromPosition(...) 回答1: Try this in a playground: import XCPlayground import AppKit let view = NSView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) XCPShowView("view", view) let txtf = NSTextField(frame: CGRect(x: 50, y: 50, width: 200, height: 50)) view.addSubview(txtf) txtf.stringValue = "falling asleep at the keyboard..."

Select all text in a NSTextField using Swift

混江龙づ霸主 提交于 2021-02-07 09:17:02
问题 How can I programatically select all the text in a NSTextField using Swift? For UITextField theres a method like textField.selectedTextRange = textField.textRangeFromPosition(...) 回答1: Try this in a playground: import XCPlayground import AppKit let view = NSView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) XCPShowView("view", view) let txtf = NSTextField(frame: CGRect(x: 50, y: 50, width: 200, height: 50)) view.addSubview(txtf) txtf.stringValue = "falling asleep at the keyboard..."

NSOutlineView row not editable by “Return” key anymore after reloading a different table view cell

萝らか妹 提交于 2021-02-05 08:11:42
问题 I'm running into the strangest issue with my NSOutlineView : Everything is set up in a storyboard, i.e. the outline view and two NSTableCellView s The two cell views are mostly the same, only one shows an icon, the other one doesn't I can begin editing an item (row) by pressing the Return key, i.e. the NSTextField that is part of my NSTableCellView enters into edit mode. This is the default behavior and works fine so far. However: After editing ends and the item was changed, I use the second

NSOutlineView row not editable by “Return” key anymore after reloading a different table view cell

◇◆丶佛笑我妖孽 提交于 2021-02-05 08:11:32
问题 I'm running into the strangest issue with my NSOutlineView : Everything is set up in a storyboard, i.e. the outline view and two NSTableCellView s The two cell views are mostly the same, only one shows an icon, the other one doesn't I can begin editing an item (row) by pressing the Return key, i.e. the NSTextField that is part of my NSTableCellView enters into edit mode. This is the default behavior and works fine so far. However: After editing ends and the item was changed, I use the second

Changing TextEditor background color in SwiftUI for macOS

≯℡__Kan透↙ 提交于 2021-01-26 04:45:55
问题 I would like to change the background color of a SwiftUI text editor on macOS. Is there a variant for the code below (used for iOS) to work for NSTextField instead of UITextView? Thanks. struct ContentView: View { init() { UITextView.appearance().backgroundColor = .clear } var body: some View { TextEditor(text: .constant("Placeholder")) .background(Color.red) } } 回答1: I have just posted an answer for that issue on a similar question here With the help of extension, you can clear the default

Changing TextEditor background color in SwiftUI for macOS

假装没事ソ 提交于 2021-01-26 04:45:28
问题 I would like to change the background color of a SwiftUI text editor on macOS. Is there a variant for the code below (used for iOS) to work for NSTextField instead of UITextView? Thanks. struct ContentView: View { init() { UITextView.appearance().backgroundColor = .clear } var body: some View { TextEditor(text: .constant("Placeholder")) .background(Color.red) } } 回答1: I have just posted an answer for that issue on a similar question here With the help of extension, you can clear the default

Programmatically make a multi-line label

人走茶凉 提交于 2020-07-03 06:16:30
问题 I need to programmatically make some labels and text fields. I can get there. //create the file name label NSTextField* newFileNameLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(objXPos, objYPos, 300.0, 20.0)]; //set properties [newFileNameLabel setBordered: NO]; [newFileNameLabel setTextColor: [NSColor whiteColor]]; [newFileNameLabel setDrawsBackground:NO]; [newFileNameLabel setEditable:NO]; [newFileNameLabel setStringValue: @"File Name:"]; [vSheetView addSubview:newFileNameLabel];

Label won't copy Text as typing - tried many solutions (MacOS app)

核能气质少年 提交于 2020-05-28 11:51:47
问题 I'm new to coding and about to tear my hair out. I have a split view set up (macOS app) and I'm just trying to get a label on the left hand side to update to text entered on the right as the user is typing. I’ve been struggling for around 15+ hours with this problem. I’ve searched extensively and tried many solutions (notably those found at Swift3: Live UiLabel update on user input), below are all the attempts that have build successfully but none change the label when entering text. I’m