I want to have command-plus as a key equivalent for a menu item, however, when I try to enter command-plus, it shows up as command-shift-equals instead of a plus. And when I press command-plus, it shows up as command-equals. Does anyone know how I can get around this?
In Xcode 8.2 when entering a key equivalent, if you hit ⇧⌘= you get a little popup button saying "alternates" inside the field. It presents you ⇧⌘= and ⌘+ as alternates (importantly, this only shows if you enter the key equivalent from the text field in the inspector, not by double-clicking the key equivalent slot for a menu item in IB). This is where I presume you are intended to choose ⌘+ if you want it presented like that.
However, that doesn't actually appear to work at least when compiling my app in macOS Sierra 10.12 / with Xcode 8.2.1. I'm posting this as a solution as the key equivalent looks correct in Interface Builder after doing this, and issue with it happens only during runtime so I assume there is a version of the Xcode build toolchain or Cocoa where this actually works.
Interestingly, editing the storyboard gives the same symptom (the equivalent works fine in IB but shows up blank ):
<menuItem title="Increase Image Size" keyEquivalent="+" id="SCO-e4-3zd">
<modifierMask key="keyEquivalentModifierMask" command="YES" />
<connections>
<action selector="increaseRowHeight:" target="Ady-hI-5gd" id="pu1-6E-HSr"/>
</connections>
</menuItem>
A third solution has the same runtime symptoms too (assign an outlet to the item and set it in code):
decreaseThumbnailSizeItem.keyEquivalent = "+"
decreaseThumbnailSizeItem.keyEquivalentModifierMask = NSCommandKeyMask
The same works when setting either NSShiftKeyMask or NSAlternateKeyMask together with + as the key.
To type a + sign you actually have to press Shift+'=', that's why when you put Cmd+ into key equivalent it shows up as Cmd+Shift+=.
This can be done programmatically. Connect the menu item to a property ("zoomInItem") in interface builder. Then set the key equivalent when the application is finished launching.
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
[self.zoomInItem setKeyEquivalent:#"+"];
}
If you have access to a keyboard with a numerical keypad, you could use the numpad + key.
You can open the xib file in a text editor add edit the menu item's key equivalent there:
<menuItem title="Zoom In" keyEquivalent="+" id="hXP-3c-xDr"/>
Related
I'm in the process of building a help book for my application, mainly using apple's documentation here, however it appears to be a little dated. In Yosemite OS X 10.10, apple's own apps have a collapsable side bar that displays the table of contents for the help bundle
Although, the side bar button is present on my own app I have no idea how to access it. Does anyone know how to access this sidebar? and provide content for our own apps?
I've just come up against the same problem, and I had to dig around in Apple Mail's help files to find out what they were using. Basically they have constructed their sidebar in HTML/CSS, and its not a part of the help viewer.
To enable the "Table of Contents" button in the help viewer, you need to use the javascript function:
window.HelpViewer.showTOCButton(bool, function, function);
For a more explicit example, the following code snippet will enable the "Table of Contents" button in Apple's help viewer, and link it to the function "toggleNavigation".
if ("HelpViewer" in window && "showTOCButton" in window.HelpViewer) {
window.setTimeout(function () {
window.HelpViewer.showTOCButton(true, toggleNavigation, toggleNavigation);
window.HelpViewer.setTOCButton(true);
}, 100);
}
The toggleNavigation function will contain code to open your sidebar.
function toggleNavigation() {
// YOUR CODE HERE
}
I found that using window.onload doesn't seem to work, but setting a timeout for 100ms did. In Mail, Apple used their equivalent of the "toggleNavigation" function, for both of the function parameters, as per the example. The third parameter is called when you press the "Table of Contents" button, but I've not worked out what the second one is for.
Maybe this question has been asked before, but I couldn't find a precise answer. I have implemented the RecyclerView widget as a list in my L test application and I want to get the 'material effect' when you click on an item form the list. I implemented an onClickListener in my ViewHolder creation and set the attribute
android:background="?android:attr/selectableItemBackground"
as a background to my list item layout (to the parent).
But none of this worked. When I click on the items NOTHING happens'. There is no effect, holo, material, none... Please point out if I am doing something wrong here... Thx
Sandra's answer didn't work for me. I needed one more property in my list item layout:
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
Note: if you get an error when pasting in the last line, then your android app is set on version 10 or below. Just right click on the error in Android Studio and set it so it will create a v11 version of your layout as well. Then, in the original layout, make sure to delete
android:background="?android:attr/selectableItemBackground"`
This is because the animation isn't supported in v10 versions of android or lower. With these two layout files set up, the animation will correctly show in v11+ versions of Android and of course it won't be shown in lower versions.
(or just increase the minSdkVersion version of your app to higher than 10)
I made a silly mistake and did not put
android:clickable="true"
android:focusable="true"
to my list item layout. I think this was not required pre L, but it doesn't matter because that was the problem in this case.
android:clickable="true"
android:focusable="true"
these lines are no longer used. just adding
android:background="?android:attr/selectableItemBackground"
working for click effect.
In Textmate there is a great shortcut to get to the context menu without using the mouse (I wish it worked systemwide!!!). It is Opt+F2.
When working on my Macbook, however, F2 is mapped to screen brightness, so I have to press fn+opt+F2, for which I have to use both hands - and that's quite uncomfortable.
Is the a way how I could map it to the right opt key, for example?
For TextMate 2 you can create ~/Library/Application Support/TextMate/KeyBindings.dict and let it contain something like:
{ "#d" = "showContextMenu:"; }
Here #d corresponds to ⌘D. See this blog post on how to construct the key equivalent strings.
Source: TextMate mailing list
Key binding files are read in the following order. A new binding for a bound key overrides the previous one:
/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
/Library/KeyBindings/DefaultKeyBinding.dict
~/Library/KeyBindings/DefaultKeyBinding.dict
/path/to/TextMate.app/Contents/Resources/KeyBindings.dict
~/Library/Application Support/TextMate/KeyBindings.dict
A relaunch of TextMate (⌃⌘Q) is required before changes take effect.
When it comes to the launch screen I can't find a unifying way to mimic the look of the application on both iOS6 and iOS7 (supporting both). Are we forced to make a regular splash screen of a logo or similar if we have a toolbar menu or do you guys have any great ideas how to solve it?
Short answer
In iOS 7, an app can use a different launch image depending on which version of iOS it’s running in. To provide different launch images, add the UILaunchImages key to the Info.plist file and use a dictionary to describe each launch image.
Background
It uses the following keys:
UILaunchImageName - A string containing the name of the PNG image file. The image file must reside at the top level of the app bundle.
The name you specify for this key should not include a filename
extension, nor should it include modifiers such as #2x, -568h,
~iphone, or ~ipad.
On disk, your image filenames may still include the #2x, -568h,
~iphone, or ~ipad modifiers as appropriate, although they are not
required. The system automatically accounts for such modifiers when
choosing which file to load.
UILaunchImageMinimumOSVersion - for iOS7 this should be a string “7.0”.
UILaunchImageOrientation – String containing one of: Portrait, PortraitUpsideDown, Landscape, LandscapeLeft, LandscapeRight.
UILaunchImageSize – String specifying width and height, ex: “{320, 480}”. You must specify the width and height with respect to
the device in a portrait orientation. In other words, portrait and
landscape images targeting the same device would have the same width
and height.
If this key is present, iOS 7 uses it exclusively to obtain launch
images.
BUT: I found that sticking to the naming convention also for iOS7 helped a lot!
This key is supported in iOS 7.0 and later.
OK – so now what?
Because I already had launch images for iOS6 and with all their specific naming conventions. I chose to make a copy of all of them and prefix the name with ”iOS7-” so as to limit my own confusion about all the different sizes and names. Making a prefix should prove to come in handy as then most of the images would immediately be loaded correctly.
The filenames:
I had these for iOS6 already, I also list the file sizes for those in need:
Default.png (320x480)
Default#2x.png (640x960)
Default#2x~ipad.png (2048x1496)
Default~ipad.png (768x1004)
Default1024x768.png (1024x768)
Default1024x768#2x.png (2048x1536)
Default-568h#2x.png (640x1136)
Default768x1024.png (768x1024)
Default768x1024#2x.png (1536x2048)
Default-Landscape~ipad.png (1024x748)
Default-Portrait#2x~ipad.png (1536x2048)
So I made a copy of all of these filenames for iOS7 (same sizes) prefixing them with "iOS7-":
iOS7-Default.png
iOS7-Default#2x.png
...
In XCode
Now to create your entry in PLIST. Go to your-name-of-application.plist. In a blank area, right-click and choose ”Add Row”. Make sure it becomes a top item and not a sub-item of some other information in the .plist.
Write:
UILaunchImages
Right-click on this UILaunchImages and select value type ”Array”.
Use the illustration below as a guide to the text and for how it will look when it is all finished:
If you open up this array so the little indicator triangle to the left points down, it is empty the first time, but if you choose ”add row” while it is open it will create a sub-line. Do that now:
Right-click on the UILaunchImages and select ”Add row”.
Right-click on this new line (item 0) and select value type ”Dict”
Continue opening this items with the triangle indicator and right-click and ”Add row”
This item you will name UILaunchImageMinimumOSVersion and set value type to “string” and the string to “7.0”
Now the following are all strings and should be at the same level as the UILaunchImageMinimumOSVersion item. In the same dict (dictionary). Create these by just choosing “Add row” for each:
UILaunchImageName – base-name-of-iOS7-launch-image. In my case this was ”iOS7-Default”
UILaunchImageOrientation - example: Portrait
UILaunchImageSize - the size of the elementary base iOS7-Default.png: "{320, 480}". The program will find all the files with permutations of the base name. Remember to select the base name of the file without ipad/iphone/portrait/landscape or .png specifications.
Note:
Xcode had already made the following items in the .plist for me after first adding iOS6 images in all available slots :-)
UILaunchImageFile~ipad … = ”Default” – so this was OK
UILaunchImages~ipad … Had two items that needed to be updated to iOS7 versions, because they where now incorrectly holding the iOS6 version. Those I had named Default1024x768 and Default768x1024 and now I just prefixed ”iOS7-” to each of the names and I was done.
Example of how it may look for those wanting to edit plist directly:
<key>UILaunchImages</key>
<array>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>iOS7-Default </string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 480}</string>
</dict>
</array>
[edit by jd: fixed spelling of "UILaunchImages"]
Highlight the project in the project browser, select "General", scroll down to "App Icons", click on "Use Asset Catalog", and select "Migrate". Your existing icons and splash screens will be automagically migrated into an asset catalog. You can then select the catalog to add further images.
To add new images you simply drag from Finder and drop into the squares for each image type.
(Caution: The catalog editor inexplicably uses a non-scrollable wide format, and you can be missing stuff off the right side if your screen isn't wide enough.)
You can also use the new image catalogue feature in Xcode 5 to manage multiple versions of launch images.
Now you can directly add the app icons and splash images in the images.xcassets,
Click on + button to add the respective image set for iphone5 with iOS 5,6,7 ,iphone4, iPad.
now no need to set the images name like default.png,default#2x.png
Be warned when using an images.xcassets repository it will not allow you to localize your splash screens.
I'm currently trying to get a French and English version of our app.
WWW> Will this 'plist' method work if you need to localize your splash screens?
I also had the same issue with an older app that I developed for iOS 7. It Archived and Uploaded fine with Xcode 6, but the "binary not optimized for iPhone5" error returned with Xcode 7. After trying a myriad of other solutions, I was only successful by removing all references to any Launch Image (since I was using a universal .xib) AND setting the deployment target from 7.0 to 8.0
Im having some issues localizing a danish app ive made. (The language, not the pastry)
I have set the CFBundleDevelopmentRegion to da_DK for danish in my info.plist, but the popup appearing for text input is still in english, even on phones running the danish OS.
How in Jobs name can i change this ?
The test device is a non-jailbroken iPhone 4S running iOS 5.1 with Danish as its iOS setting, and a danish itunes account associated.
I do not use .xibs for designs. all interfaces are programmed as viewcontrollers.
In the Xcode's file tree (Project Navigator) select your project. in the right hand pane select your project again. select Info and add your language.
I created a sample project, this is the result:
You can do this directly in the info.plist. Something like this:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
<string>es</string>
<string>ja</string>
</array>
Try adding/setting the "Localized resources can be mixed" flag in Info.plist to YES.
You must localize your app in Danish to make the standard UI elements appear in that language. This is to avoid having a UI with mixed languages.
If you don't use xibs, you'd usually do this by adding a Localizable.strings file to your project. In Xcode's "Add File" dialog, you can use the "Strings File" template (under "Resources") for this.
To actually localize the strings file, open the file inspector (⌘ ⌥ 1) and click the + button in the "Localization" section. You'll end up with the file being displayed as a group in the project navigator, with a sub-entry for each language.
The strings file has the format:
"Label_Text" = "Smørrebrød";
(don't forget the semicolon)
To use localized strings in your code, you can use the NSLocalizedString macro like this:
myLabel.text = NSLocalizedString(#"Label_Text", nil);
(The second parameter is for a comment. This can be useful if you use the genstrings tool to extract localizable strings from your code and give the resulting file to a professional translator.)
If you use the English strings as keys, you can leave the English version of Localizable.strings empty (but don't delete it).
Having a Localizable.strings file in the language that the user has selected will also cause standard UI elements, such as the editing menu, photo picker, and so forth, to appear in that language.
If you can't get it working the official way, as provided by #vikingosegundo, you can do this with some creative engineering (Creative as in, oh my god that is dangerous). I discovered this method when I accidentally overrode [NSBundle localizedStringForKey:value:tableName:].
1) Add a category to NSBundle with the following methods:
#import <objc/runtime.h>
+ (void) load {
Method original, swizzled;
original = class_getInstanceMethod(self, #selector(localizedStringForKey:value:table:));
swizzled = class_getInstanceMethod(self, #selector(swizzled_localizedStringForKey:value:table:));
method_exchangeImplementations(original, swizzled);
}
- (NSString*) swizzled_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
NSLog(#"Key: %#. Value: %#", key, value);
return [self swizzled_localizedStringForKey: key value:value table:tableName];
}
2) Where I simply log the key/value, you want to put an if ([key isEqualToString: xxx] ) block. In there, you want to catch (at least some of) the following key values: Cut, Copy[Menu], Select, Select All, Paste, Delete[Menu], Replace..., Define, Speak, Pause. These are the default values that can appear there.
3) When you have caught the value you can look up in a custom table or use hardcoded values. If you look up in a custom table make sure you have a catch in your swizzled method to avoid infinite looping in your custom table.
NB: Why do you need to swizzle? Because this over-rides all Apple text for you app. You will still want the defaults for all the other strings, so you need to swizzle to get the defaults for the strings you aren't interested in.
Good luck.
Paul
Search if your .xib is localized (you'll find it in the inspector on the right panel) if so go to your Project/Target-Settings press the +-Sign and select "Duplicate English to Danish" or something which means the same (I can't check the right item at the moment)
Btw it's called iPhone 4S.