Is there a way to change the alignment of all the textual elements (i.e textfileds, button titles, labels, navigation bar titles etc) throughout the app at once programatically? Actually I am developing a multi language app that has a language in which the text alignment is RTL. I dont want to set the alignment of every text element manually.There are some restrictions, so NSTectAlignmentNatural could not solve my problem. Actually the translations for languages arecoming through an API and that too in unicode format. So, how would the system detect what language is going to be displayed so that it could decide the alignment.
You can use UIAppearance to set properties of ui elements throughout your entire app. This will work for all classes that adopt the UIAppearance protocol (UILabel, UIButton, etc).
For eaxmple, the following code will change the text alignment of all labels in your app:
[[UILabel appearance] setTextAlignment:NSTextAlignmentRight];
IIRC, UINavigationBar does not support UIAppearance, meaning that you'll need to use a custom label for the title.
Replace all those elements with a thin custom class of your own creation that you can wire up to change this property based on the locale.
Related
I have a requirement to create a button in a Windows 8.1 app which has an icon and a text label. The icon will be a symbol from Segoe UI Symbols and the text label will be Segoe UI Semibold at a smaller text size.
I want to be able to reuse the button in different places within the app, using different icons and text labels.
How show I go about this? I could create a button and then edit the ContentPresenter to have a horizontally oriented stack panel with two TextBlocks, but then how could I reuse this? And how could I change the text in the two different text blocks?
Should I create a separate custom control with separate dependency properties for each of the textblock strings? I'm interested in hearing what you would do.
thanks
Create a simple Style. To make it easy, I would base it off the standardized AppBarButton style. You can format it to whatever size you want (I have done something similar to make a larger button or one with text on the side).
Have the main icon simply be a ContentPresenter which binds to the Content using a TemplateBinding. Make sure to set the FontFamily to Segoe UI Symbol. Have the text label pull from AutomationProperties.Name, similar to how the AppBarButton style does.
Then, whenever you want to use this just do:
<Button Style="{StaticResource MyCustomButtonStyle}"
Content="" // Where "000" is replaced by the number of the icon you wish to use.
AutomationProperties.Name="Text Label"/>
This should be extensible and easily reproducible to whatever location you need. When copying over the AppBarButton style, I suggest removing the artificial size limits (specifically the width of the main content Grid). I do suggest either giving the Text Label a fixed size or having it pull its size from the specified parent Width, so that it will Wrap correctly.
Hope this helps and happy coding!
Are you desiring to create something like for an AppBar? Take a look at AppBarButton and the style/types it supports. In Windows 8.1 we added some things around SymbolIcon specifically. Since you basically want two pieces of 'content' for your style you'll have to re-purpose one property (unless you create a custom control which doesn't sound needed for this scenario). Using AutiomationProperties.Name for the visible label is a good idea because it will also help with accessibility by default for those users.
Investigate the style for AppBarButton to get you started.
My app has all different kind of NSViews, including NSTabView, NSButton, NSTextField, NSPopupButton and so on.
I would like to change all display text to a certain font and with certain font style.
is there anyway to set the default font and font style in cocoa app?
I have tried:
How to loop through subviews in order to get the text of NSTextViews
however it doesn't work with NSTabView and NSButton.
I think that there must be an easy to do so, it's just I don't know what it is.
Please advise.
There isn't a built in way to do this (ie. by setting a key in Info.plist). You really do need to go through all the controls in your app, one way or another, and set a custom font for them. There are a few possible approaches. One is to use a custom subclass for all the controls for which you need to use a custom font. The subclass can be really minimal, it just needs to set the correct font upon initialization, possibly preserving other font attributes (size, color, etc.) setup in Interface Builder. Another option is to do as you've suggested and go through each subview in your app, check to see if it responds to -setFont:, and set your custom font if it does. I've used the first approach (subclass) with good success.
I would like to set a custom color for the keyboard that is associated with a UITextField. I see that I can set the UIKeyboardAppearanceType, but I would like to be able to set the color to arbitrary color, rather than just change to a different default setting. I was hoping it would be as simple as something like this:
keyboard.tintColor = [UIColor colorWithRed:...]
Any suggestions?
There's no public API to access the system keyboard, so you're out of luck without re-writing UIKeyboard from scratch (which is a bad idea), or finding some private API to do the job (which is a bad idea if you want to submit to the App Store).
You could use Alert style keyboard and place a view in the background with a background color of your choice. This will make the keyboard a different color.
In Xcode look for the 'Keyboard Look' attribute in the Text Input Traits section of the Attributes Inspector. Can toggle between Light/Dark.
Is it possible to change UITextView`s color in particular range or particular word? If a word appear more than once in a view then change the color of that word.
You'll need to use NSAttributedString. I recommend checking out AliSoftware's OHAttributedLabel which extends UILabel and adds support for setting text via NSAttributedString among other helpers. I'm using it in a current project and it's pretty fantastic.
I solve the problem. I created subclass of UILable and UITextView used core text (CATextLayer) as a layer on label/textview and NSAttributedString will store all the information about the font and color
I'm fairly new to iPhone programming and am trying to implement a double-component PickerView. At this point the picker works fine in terms of taking user input, created with Interface Builder. However, I need to change the font size to accommodate the text length in each column. I very much would appreciate any link to a straightforward method to creating a multi-component picker with an adjustable font size. Seems like it is not possible if Interface Builder is used to create the picker. So far I have not found any code links that address this issue in detail.
Thanks in advance.
You need to implement the delegate method...
pickerView:viewForRow:forComponent:reusingView:
... and then alter the font of the UI element inside the provided view. I think the default is a UILabel. Alternatively, you can provide your own custom view.