I would like to create an NSMenuItem with more than one line of text in it, and I'd also like an icon to appear next to both lines of text. I can't use a custom view, because then it wouldn't highlight correctly, and I can't just put a newline in the menu item's title, because the newline gets turned into a space. What should I do?
It turns out that although you can't put a newline in the title property of a menu item, you can put a newline in the attributedTitle. Something like this will work:
item.attributedTitle = [[NSAttributedString alloc] initWithString:#"line 1\nline 2"];
Related
XCode's auto completion can sometimes be a pain in the butt, here an example:
It seems impossible to just type in some content to replace the completionHander placeholder without deleting the entire highlighted section of text - if I hit tab and start typing then Xcode deletes everything highlighted in blue, when what we want to do is keep the ^(NSArray *placemarks, NSError *error) part and type in our own content in place of the completionHandler placeholder.
Are there any tricks to keep auto completion enabled for cases when its useful, but to get this and similar examples usable instead of unusable?
Hit Tab, but instead of starting typing, just press Enter. Xcode will expand the selection into a block with empty implementation.
Before:
After:
When the placeholder for the block is highlighted, press Return. It'll be replaced by the complete block declaration and a set of empty braces, with a highlighted placeholder inside for you to start typing code for the block's body; e.g.
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
<code>
}]
I am just starting out in xCode and I have built a very simple (mac, not iPhone) app that pops up a window with a text field, a label and a button.
I can get the app to pop up a message box with the string value of the text box, but I can't seem to set the string value of the text field with some default text.
The code I am using to try to populate the text field is:
[_txtBox setStringValue:#"Hello World"];
the set string method is the only method that looks like it should set the value of the box. The program runs with no errors and when I click on the button, no error's are thrown.
If the text field contains text, the text displays in the label as it should.
If I place the line of code above just before the code that reads and outputs the text field, then instead of the text box showing that text box, the text box text just disappears as if I had over written the contents of the field with an empty string. The label is also blank.
Suggestionsn would be welcome; the almost identical expression I am using on the label works fine:
[_lblOutPut setStringValue:_txtIP];
So I have no idea what I am doing wrong...
Cheers!
Dave
Check whether you are using "NSTextField with NumberFormatter" or "NSTextField".
"NSTextField with NumberFormatter" allows only numerals. If you try to set NSString it will display only an empty string.
Try this
[_txtBox setStringValue:#"123"];
Now, If you are getting 123 in your output, then definitely you are using "NSTextField with NumberFormatter"
For text input, are you using a NSTextField or an NSTextView? They are vastly different in handling, setStringValue: works for NSTextField, yet NSTextView requires an attributed string to be passed to [[textView textStorage] setAttributedString:...].
Are you sure you connected the right way the outlet in IB?
what's the output of
NSLog(#"%#", _txtBox);
(put it before the setStringValue)
I need to implement custom space separator with custom width between two part of paragraph in text view:
AAAA AA A -------- BBB BBBBB B
This is separator must be included as non-editable character. So user can't delete it or modify.
I understand, that i must overload standard behavior of textview in some points (for example, when user press "delete" right after separator nothing will be deleted)
I have several ideas how accomplish this task:
Use elastic glyph attribute (there are mentions in documentation about it). But I can't find any documentation about how to use it.
Use tab symbol and NSTextTab for each paragraph, and in any modification to the paragraph recalculate position of tab.
I will be very grateful for any right direction.
I had a similar problem and wound up inserting blank images of the desired width into the textview. The code for implementing this is here:
Changing the width of the space character in NSTextView
I've been playing around with NSTextView and have applied some paragraph styles to certain lines. However, when I type enter and get a new line, the attributes that I applied to one line are bleeding into the next.
I want to be able to apply a paragraph style to one line and have the next line be formatted in the default way. You can see what I mean from the screenshots.
When I add some spacing between paragraphs via NSParagraphStyle, the same spacing applies to the newline, which makes the whole thing look pretty shotty. Basically, I am looking for a way to reset the paragraph style for an empty line.
I have tried [MyTextView resetTypingAttributes:theAttributes] to no avail, since you first have to start typing for the new attributes to apply. Just to be clear, the line below the text in the screenshot is the cursor, which is really far down there as a result of the paragraph spacing.
Screenshot:
It seems that you have to use setTypingAttributes on the textview.
Sometimes when I type certain words, XCode will offer to autocomplete with several options. If I press enter, it automatically puts the curser on the first option and selects it so when I start typing that part gets replaced. After that, how do I immediately get to the next option, without having to double click it?
For example, if I type the following:
UIAlertView *alert = [[UIAlertView
alloc] ini
Then Xcode offers to autocomplete with the following:
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:(NSString
*)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString
*)cancelButtonTitle otherButtonTitles:(NSString
*)otherButtonTitles
Everything that appears above in bold is highlighted, meaning they are to be replaced by the programmer. If I press enter to accept the autocomplete, Xcode will put in the above code, and select the first highlighted item, which is (NSString *)title. If I start typing something, this is immediately replaced by what I type. When I'm done replacing this, I want to move directly to replacing the next highlighted item, which in this case is (NSString *)message. I can do that by double clicking on it, but is there some kind of keyboard shortcut that will get me directly there?
Press Control.
Or press Esc to enter the list of completions.
Edit: Aha! Now I know what you mean. You want Control/.
Press the TAB key to move to the next highlighted item and SHIFT + TAB to move backwards through the same list.