nstextfield

Why do hyperlinks sometimes not show in an NSTextField with an NSAttributedString?

隐身守侯 提交于 2019-12-04 09:02:51
The text I use in an NSTextField is loaded from a file as follows. NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]; NSAttributedString *as = [[NSAttributedString alloc] initWithPath:path documentAttributes:NULL]; [creditsLabel setAttributedStringValue:as]; [creditsLabel becomeFirstResponder]; The hyperlinks in the window don't render in blue underline unless I first click somewhere on the NSTextField, as per the two screenshots. How can I make these hyperlinks always look like hyperlinks? Here's the RTF: {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250 {

Objective c checking whether text field is empty

走远了吗. 提交于 2019-12-04 08:49:50
问题 Here's the code: - (IBAction) charlieInputText:(id)sender { //getting value from text field when entered charlieInputSelf = [sender stringValue]; if (charlieInputSelf != @"") { //(send field if not empty } } This sends it even when the field is empty; therefore, this does not work as I want it to. 回答1: Simply checks for nil and if length of text length is greater than 0 - not empty if (textField.text && textField.text.length > 0) { /* not empty - do something */ } else { /* what ever */ } 回答2

Bind properties in Swift to NSTextFields

流过昼夜 提交于 2019-12-04 06:26:08
问题 I'm working on a unit converter written in Swift that will automatically display the updated units within the appropriate NSTextField s. For this example, if the user inputs minutes into the minutesField , the secondsField and hoursField should automatically update to display the converted values from the properties. Below is an example of the code in my view controller: import Cocoa class ViewController: NSViewController { @IBOutlet weak var secondsField: NSTextField! @IBOutlet weak var

NSTextField: do not strip trailing spaces while center-aligned

大城市里の小女人 提交于 2019-12-04 06:24:18
问题 My crusade against static text NSTextField goes on. The question for today is: Why do center-aligned NSTextField -s even dare to strip trailing spaces from the lines they are given? Why don`t they strip leading spaces then? But, most importantly, how do I stop them from butchering my text? P.S.: if you`re wondering why I want that, refer to this question of mine. P.S.#2: seems like a similar question has been asked before — to no avail, though. 回答1: Based on a quick experiment: Select the

Secure text .echosbullets not working for password field

China☆狼群 提交于 2019-12-04 05:11:59
问题 Here's what I've got: @IBOutlet weak var password: NSSecureTextField! @IBOutlet weak var shwpswd: NSButton! //Checkbox @IBOutlet weak var pswdcell: NSSecureTextFieldCell! //Cell @IBAction func shwpswd(_ sender: Any) { if(shwpswd.state == 1) { pswdcell.echosBullets = false // Turn the Secure text into regular text } else if(shwpswd.state == 0) { pswdcell.echosBullets = true // Secure text } } Everything seems to run fine, except the text in the password field doesn't change states between

NSTextField delegate notifications — how to get text?

Deadly 提交于 2019-12-04 03:10:36
I've been trying to learn to use Xcode, but I'm getting confused with how to register that NSTextField has changed. Essentially, I have an NSTextField and a button. Clicking the button does stuff with the text in the field. However, I want to be able to get the text of the field without needing to use the text field "Action:send on end editing." That is, I want to be able to enter text and immediately press the button, without hitting enter or tabbing out of the text box. It seems like the way to do this would be by setting a delegate for my NSTextField that responds to - (void

Change border color of NSTextField

孤人 提交于 2019-12-03 17:39:09
问题 I want to change the border color of NSTextField object, but I can't achieve it. I already have tried many solutions EX: be subclass, draw background... is there anyone who can resolve this issue or share any ideas? Please let me know. Many thanks. 回答1: Use NSBezierPath - (void)drawRect:(NSRect)dirtyRect { NSPoint origin = { 0.0,0.0 }; NSRect rect; rect.origin = origin; rect.size.width = [self bounds].size.width; rect.size.height = [self bounds].size.height; NSBezierPath * path; path =

Problems setting FirstResponder in Cocoa Mac OSX

纵然是瞬间 提交于 2019-12-03 16:27:06
Im working on a tiny app just to learn cocoa, and Im having a hard time with setting FirstResponder to some NSTextFields. When the view opens, I want the first NSTextField, clientNumber, to be selected, so I trigger [clientNumber becomeFirstResponder] at the end of my loadView method, but it does not select the text field. But when I click the button that fires the (IBAction)addToArray method, it selects the right text field. Further do I have another text field, it should contain integers only, so I have a crude verification for it. When the content is not a int, I get a beep, just like it

Clickable url link in NSTextFieldCell inside NSTableView?

依然范特西╮ 提交于 2019-12-03 15:50:59
I have a NSAttributedString that I'm using in a NSTextFieldCell. It makes several clickable url links and puts a big NSAttributedString inside the NSTextFieldCell. Whenever I am viewing the NSTextFieldCell normally and it's highlighted, I cannot click on the links. If I set the TableView so I can edit each column or row, when I click twice, go into Edit mode and view the NSTextFieldCell contents, my links show up and are clickable. When I click away from the row, I can no longer see clickable links. I have to be in "edit" mode to see the links or click on them. I feel like there's some setting

Autocomplete with twitter usernames in text field (cocoa)

。_饼干妹妹 提交于 2019-12-03 09:08:55
I was looking at NSTokenField, NSTextField and NSTextView with no luck to do the following: I am writing a Twtitter client and when you want to twitter a new Tweet then you begin to write in a text field for example: Going to make coffee, @pe When you begin to write a @ then I would like to help the user to autocomplete the username for example @peter . I have a NSArray with the usernames like: NSArray *usernames = [NSArray arrayWithObjects:@"@andreas", @"@clara", @"@jeena", @"@peter"] What should I do to enable a simple autocompletation? I'd be happy if you would have to press F5 or something