Get text from NSTextField [duplicate] - objective-c

This question already has answers here:
Get value from NSTextField
(4 answers)
Closed 8 years ago.
I'm new to OS X development in Xcode and was wondering how to get the text from a text field and NSLog it, I would also like to pass it to a string. Any help?

The -stringValue method can be used.
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:...];
NSString *text = [myTextField stringValue];
NSLog(#"%#", text);
Do not be fooled by those who say that text is a property of NSTextField.

Before asking questions like this, please read up on the documentation here:NSTextView. Also please take a look at all of Apple's documentation here:Apple Documentation

Related

How to modify value in NSArray object? [duplicate]

This question already has answers here:
How do you change the elements within an NSArray?
(3 answers)
Closed 7 years ago.
I want to modify value in NSArray at index 0.
Here is sample program
NSArray *test = #[#"abc",#"rec",#"myPM"];
NSLog (#"%#",[test objectAtIndex:0]);
test[0]=#"001";
NSLog (#"%#",[test objectAtIndex:0]);
Here I am getting lot of errors. please help me in this.
You should use an NSMutableArray
And with this method :
[yourArray replaceObjectAtIndex:INDEX withObject:OBJECT].

How to change the color of a specific word in ios [duplicate]

This question already has answers here:
How do you use NSAttributedString?
(15 answers)
Closed 9 years ago.
I want to change the color of a particular word from a sentence in IOS 5.
Let my string be NSString str = #"Your password is abc";
I want to change the color of password 'abc'.
Please help me.
Thanks in advance.
In IOS 6 you could change the font, textColor, and textAlignment for particular word through attributedText you could find the documentation for this here
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextView_Class/Reference/UITextView.html
Same question is answered in stackoverflow the link of the question is as follows
Bold & Non-Bold Text In A Single UILabel?
I think you are looking for this thing, hope it will work for you.
For a string like firstsecondthid, you can do like this. With first written in RED, second in GREEN and third in BLUE.
Example code:
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:#"firstsecondthird"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];
You can use RTLabel just set attributed text in the rtLBLObj.text it will show you relevent output.Just download and drag RTLabel.h and .m file in your project. you can down it from RTLabel
As the previous answers have mentioned, you need to use an NSAttributedString to store formatted text.
However, native support in iOS for attributed strings in UILabels was only introduced in iOS 6.
If you want to support iOS 5 and below, there are many libraries around for displaying an attributed string. I would recommend using TTTAttributedLabel.

Combining two strings for a label's text [duplicate]

This question already has answers here:
Setting a cell's text with multiple JSON objects
(3 answers)
Closed 9 years ago.
Real beginners question here. I'm doing some tutorials and I'm expanding on them with scenarios that might come in to play.
Anyhow, I know that the following works:
lblCopyStatus.text = #"Test";
But how would do:
lblCopyStatus.text = #"Test" & lbltest.text;
e.g. get the text from another label into the text. I hope that makes sense :)
For example:
lblCopyStatus.text = [NSString stringWithFormat:#"Test %#", lbltest.text];

Format String is not a literal string (potentially insecure) warning [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: “format not a string literal and no format arguments”
I have the following line of code that is in my app that a Developer worked on. I am learning the basics of Objective C and as I was updating the App to be iPhone 5 compatible, I see the following warning (I did not change his code) Format String is not a literal string (potentially insecure). The code is as follows;
self.progressHud.labelText = [NSString stringWithFormat:message];
I don't know exactly what this means and don't want to upload anything that can either be a security issue or get rejected by Apple. Any and all help is appreciated from you all.
Use the following Lines:
self.progressHud.labelText = [NSString stringWithFormat:#"%#", message];
In objective C, this line get the values from any format such as int,float etc to display the Label. because UILabel and IBOutlet Elements only display the NSString values.
However, if you don't need to create a string with multiple variables, it would be more efficient to simply use:
self.progressHud.labelText = message;

Deprecated error [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
UIKeyboardBoundsUserInfoKey is deprecated, what to use instead?
I have the following code with an issue which I would love to remove:
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
On the second line of the code I get the message "UIKeyboardBoundsUserInfoKey is deprecated".
I,ve read similar error messages on the forum and tried a few things but my newby mind can not fix it.
You should check out the docs anytime something is marked as deprecated. You will usually find info about what has replaced the deprecated item. In this case, the Keyboard Notification User Info Keys section of the UIWindow reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html
Use UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey instead of UIKeyboardBoundsUserInfoKey
it means that DONT USE UIKeyBoundsUserInfoKey. because it is not present anymore in the new iOS xcode... so try to use the later or different key..i.e look at this tutorial
http://www.w3bookmarks.com/mobile-application-development-tutorial/iphone-questions-uikeyboardboundsuserinfokey-is-deprecated-what-to-use-instead/
You can use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardBoundsUserInfoKey.