dynamic button text iphone - iphone

If you want to make a multilingual button on a native iPhone app, where it can be one language by default, but based on your settings, show different text on the same button, how would you go about it?
Is it also possible to style (e.g. with text-shadows and custom fonts) the text on the button?
I'm not an iOS developer, but I'm attempting to provide designs for an iOS developer and don't understand the limitations (yet) when going from CSS3 to iOS UI elements.
So far, iOS development appears to be like creating image-maps where none of the CSS logic is applicable from web development and almost all UI elements appear to need all states as flattened images. I thought the controls were more dynamic but haven't found the right terminology for results from google to be very forthcoming on the topic.

U can use NSLocalizedString for multilingual text on button.
Configuring Button Title
titleLabel property
reversesTitleShadowWhenHighlighted property
– setTitle:forState:
– setTitleColor:forState:
– setTitleShadowColor:forState:
– titleColorForState:
– titleForState:
– titleShadowColorForState:
Also set Custom font like this:
yourButton.titleLabel.font = [UIFont fontWithName:#"Courier" size:22.0];
if u want to add gradient to button then u will have to use CALayer like this:
yourButton.layer = //any modification in button's layer here
For more refer UIButton class reference

Related

Can I use the system Touch Bar icons in my app?

I am trying to add a "New" button and a "Search" button for my app onto the Touch Bar. In system apps, these are a plus sign and a magnifying glass, respectively. Is there a way to use these system icons on my touch bar buttons, such as in UIBarButtonItems? If not, how can I set a touch bar button's content to be a magnifying glass or plus sign? I am using Swift. Thanks.
Apple provides many system icons that you can use in your app.
The Human Interface Guidelines has a nice visual reference of all of the icons available here. These can be referenced in your app by using the associated NSImage.Name constant (also described in the HIG).
As an example, the new and search images can be gotten using:
let addImage = NSImage(named: .touchBarAddTemplate)
let searchImage = NSImage(named: .touchBarSearchTemplate)
Maybe you could find those icons in the system files, copy them and use them in your application, but I would not recommend it. They are Apple's intellectual property and you are not allowed to use them for public projects.
You should search on sites like flaticon.com for similar artworks or create them yourself.

How do I create a NSToggleButton in Interface Builder?

I want to make an NSToggleButton because it suits my needs perfectly: show one image when toggled on, another when it's toggled off.
From Apple's Developer website:
"After the first click, the button displays its alternate image or title; a second click returns the button to its normal state.
This option is called “Toggle” in Interface Builder’s Button Inspector.
Available in OS X v10.0 and later."
- Source
When looking at the Round Rect Button I created in Interface Builder, however, I can't find a "Toggle" attribute. My google and StackOverflow searches yield only questions around attributes for the control, but I haven't found a tutorial for creating this button in particular.
How do I create a NSToggleButton in Interface Builder? Where is it in the Object library?
The source you provdided is for OSX programming. Not iOS however this can be implemented yourself. A UIButton is just a UIView so add a UIImageView as a subview then when the button is clicked set hidden to either YES or NO
NSToggleButton is an AppKit class -- MacOS X only. You won't find it if you're building an iOS app. Classes from the Foundation framework have an NS prefix and are available in iOS (NSArray, NSDictionary, etc.), but the user interface classes in iOS are in UIKit and have a UI prefix. Take a look at UISwitch for similar functionality.

which multi-selection can be implemented in iphone (Registration page)

I have multi-selection dialog(drop-down) in Android where user selects all options applicable to him in registration page.What can be used in Iphone for the same purpose ?
And selecting a few options will unhide few textfields which is mandatory to fill.
Let me know what can be my approach.Please share any open source code links.
Thanks in advance.
No, there is no such thing within the iOS SDK and that is for a good reason - those elements are just not pretty, funky and usable well enough when acting on a touch display.
Consider using UIPickerView or UISegmentedControl instead. Maybe also have a look at Action Sheet.

Using iOS 5 rich text editor

as you know the Mail app in iOS 5 have a rich text editor is there any possible way to use this feature for a regular UITextView ?
I know of two fundamental approaches to creating a rich text editor in iOS 5:
Use Core Text and a custom view. I don't have any experience with this approach.
Use a UIWebView (instead of a UITextView) and the contentEditable HTML attribute. The basic idea is to load a custom HTML document from your app resources directory. The bare minimum that it needs is this:
<div contentEditable>TEXT_PLACEHOLDER</div>
To initialize the rich text editor view:
1. Load the contents of this file into an NSMutableString and replace the TEXT_PLACEHOLDER string with the text you want to edit.
2. Send the loadHTMLString:baseURL: message to the UIWebView with that HTML string.
Now you have a UIWebView displaying your text inside a div with contentEditable. At this point, you should be able to run your app tap on the text, and be presented with a cursor and be able to add/remove text. The next step is to add rich text formatting functionality. This is done with a set of simple javascript function calls. See the Mozilla documentation on contentEditable for a great reference. You will also want to add a Javascript function to your HTML template file like this:
function getHtmlContent() { return document.getElementById('myDiv').innerHTML; }
So you can easily retrieve the edited text as HTML using [myWebView stringByEvaluatingJavaScriptFromString:#"getHtmlContent()"]. You can also add custom context menu items like you show in the screen shot in your question.
If you have access to the Apple iOS dev center, the WWDC session Rich Text Editing in Safari on iOS talks all about this approach.
A variation of this approach is to use a third-party rich text editor like TinyMCE. I've heard of some success with integrating this into a UIWebView in iOS 5. Again this relies on the contentEditable attribute.
Here is my implementation. Still haven't added UIMenuController functionality, but it's planned to be added soon.
https://github.com/aryaxt/iOS-Rich-Text-Editor
The iOS 5 rich text edit control is also present in the notes app in iOS 4 (make a rich text note on the computer and sync it to see).
This is a custom Apple-made control which they use in their own apps, but it is not published in any official developer API. It's probably in the SDK somewhere, but because it is undocumented, even if you find it and use it, Apple will reject your app.
Basically, if you want a rich text control you will have to make your own.
Edit: Try using this: https://github.com/omnigroup/OmniGroup/tree/master/Frameworks/OmniUI/iPad/Examples/TextEditor/. I haven't used it, so I don't know how well it will work. (Link from this question)
look at https://github.com/gfthr/FastTextView which is more good open source editor than Omni editor

UIBarButtonSystemItem enum - Missing Icons?

I posted a question about mimicking the interface of the Maps application and have just come across another area where i'm unsure about the UIToolbar and UIBarButtonItem's.
In the Maps application, there are two buttons which don't seem to have any constant defined in the UIBarButtonItem documentation
At the bottom left of the app is the "location" icon and when clicking "directions" there is another "switch route" icon, neither of which are defined in the UIBarButtonItem.h
I'm guessing that these haven't been added to iOS 4 yet? Does this mean that the only way to include such buttons/images is to use the initWithImage:style:target:action: method when creating a UIBarButtonItem?
This isn't a problem, although finding similar images would be pain, I just want to make sure i'm, not reinventing the wheel when trying to include such elements.
Also, I note that whilst all the other UI elements can be styled in terms of color, the PageCurl button item doesn't seem to want to change at all. Ie: I can make all of the other toolbar buttons a different color to the default but the page curl refuses to change. Perhaps i'm missing something simple here?
Thanks for reading!
Correct, from the iOS documentation here are the only system icons available by default. You can safely assume that nothing outside of this list exists and you have to use your own image for it if you want something different:
typedef enum {
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo, // iOS 3.0 and later
UIBarButtonSystemItemRedo, // iOS 3.0 and later
UIBarButtonSystemItemPageCurl, // iOS 4.0 and later
} UIBarButtonSystemItem;