大家好,抱歉我的英语不好
我使用 xcode 和界面生成器开发了一个可口可乐应用程序,其中包含几个标签和 nstextfield 以及一个发布按钮。
我想在点击文本时动态控制文本字段(如果不允许使用字符,则为文本着色或控制长度)。
我找到了很多解决方案,但我不知道我必须在我的可可应用程序中实现代码:(但是当我单击发布按钮时我可以控制我的 nstextfield,但不能在点击 nstextfield 时控制我的 nstextfield。
我为此搜索了很多时间......
感谢您的帮助!
Hello every one and sorry for my bad english
i develop a coca app with xcode and interface builder with few label and nstextfield, and a post button.
I want to control dynamically my textfield when i tapping my text (color the text if a character is not allowed or control the lenght).
I have found many solution but i dont know where I must implement the code in my cocoa app :( yet I am able to control my nstextfield when I click to the post button, but not during tapping in nstextfield.
I search many hours about that....
Thanks for yout help !
发布评论
评论(1)
您可以控制文本颜色或字体大小,甚至可以通过设置与
NSTextField
关联的属性来控制文本字段是否启用。如果您想在点击
NSTextField
时进行更改,请设置一些类(也许是您的窗口控制器?)以符合NSTextFieldDelegate
协议,然后将其连接到NSTextField
的 >delegate 属性(通过 XIB 或以编程方式,通过NSTextField
`setDelegate' 方法然后,当点击
NSTextField
时,您可以捕获这些点击事件。通过委托方法发生,例如:<代码>[控制: textShouldBeginEditing:] (当您单击文本字段,或者按 Tab 键定位到某个位置,或者每当文本字段成为下一个在键盘中键入文本的位置时,就会调用该函数)。
到目前为止这有意义吗?
您可以在 Google 上搜索到许多
NSTextFieldDelegate
示例,并且可以在此处找到问题和答案,喜欢这个。You can control the text color or font size or even if the text field is enabled or not just by setting properties associated with your
NSTextField
.If you want to change things when tapping in your
NSTextField
, set some class (your window controller maybe?) to conform to theNSTextFieldDelegate
protocol and then connect it to thedelegate
property of theNSTextField
(either via the XIB or programatically, via theNSTextField
`setDelegate' method.Then, when clicking on the
NSTextField
, you can catch those click events happening via delegate methods like:[control: textShouldBeginEditing:]
(which gets called when you click on the text field, or if you tab into position, or whenever the text field becomes the next place where text typed into the keyboard will appear).Does this make sense so far?
There are lots of
NSTextFieldDelegate
examples that you can Google up and questions with answers you can find here, like this one.