When our app runs in a right to left language like Hebrew or Arabic, the SwiftUI views automatically flip the positions of our views to be right to left. Some of this is very helpful, but certain views should not be flipped.
We tried .flipsForRightToLeftLayoutDirection(false) on the views but this didn't prevent them from being positioned differently when running with the scheme set to Hebrew or Arabic.
Would appreciate any help. Thank you!
You can force the layout direction using .environment:
.environment(\.layoutDirection, .leftToRight)
Related
I see that iOS9 and xCode7 introduced a new field called "semantic" into storyboard config. A google search did not reveal relevant results on top.
What is the significance of the view semantic field?
There is a new internationalization support in iOS 9, which enables flipping of the interface from left to right and vice versa depending on the current system language. You can choose Arabic language to test it. Arabic is read from right to left, so the interface is flipped.
Here you can read the Apple's guide on it.
The property "Semantic" in the storyboard is a rule which allows the iOS to know if the view should be flipped or not. There are multiple options:
Unspecified - The default value for views. The view is flipped when switching between left-to-right and right-to-left layouts.
Playback - A view representing the playback controls, such as Play, Rewind, or Fast Forward buttons or playhead scrubbers. These views are not flipped when switching between left-to-right and right-to-left layouts.
Spatial - A view representing a directional control, for example a segment control for text alignment, or a D-pad control for a game. These views are not flipped when switching between left-to-right and right-to-left layouts.
Force Left-To-Right - A view that is always displayed using a left-to-right layout.
Force Right-To-Left - A view that is always displayed using a right-to-left layout.
Source - Apple's documentation
I am working on an application, where I have to implement arbic as well as english locale.
I have made seperate storyboards for both languages. Problem is autolayout constraints are automatically flipping my views. Is there anyway to stop auto flipping for arabic locale?
I want to design views myself for arabic.
Thanks
Constraints by default respect language direction, but you can turn this off by selecting the constraint, and then in the Attributes Inspector, unchecking the Respect language direction in the First Item and the Second Item pop down menus.
Note that that option isn't available for all constraints.
I have a problem that the position of a button \ image is changed according to the language localization.
e.g. in Hebrew the alignment is right-to-left in opposite to English.
this causes the buttons \ images to be positioned on the other side of the screen, in oppose to English position.
how do I disable ios from re-positioning the buttons (according to localization)?
How many languages are there for localization in your application?
If you think that there are more problems in UI then create separate .xibs file for separate localization.
Please check the link. This will help you.
https://www.clairereynaud.net/blog/getting-your-iphone-app-ready-for-localization/
I've found a simple way for doing this:
go to the controller you want to fix it's position, and select it's constraints.
set Direction property to "Left to Right" instead of Leading to Trailing".
How do I autosize Labels so they contain all the text, but don't take up any more space then necessary and stay vertically spaced the same whether the user is in portrait or landscape mode?
I am trying to implement a simple control that displays information about my app in paragraph form. It will have Headings, and Paragraphs. I am having problems correctly positioning things relative to each other and have them auto adjust as the user rotates their device and changes orientation.
In the example below, I have 4 labels. 2 are for headings and are bolded with larger font, 2 have standard font, but are long and have lots of text. I want to be able to have all the text visible on each label and have none cut off. I also, want all the labels as close as they can be to each other. So, their containing rectangles have to change based on all of the other label's height. So when I change from landscape to portrait orientation, the paragraphs may take 8 lines instead of the 3 lines it takes in landscape mode. I want the controls to shift to have the same amount of Vertical white space between each of them.
Here is a sample:
About this program
Thank you for downloading this app. It is designed to do some
wonderful things and will make all your wildest dreams come true.
Help
In order to use this program, use the tab bar at the bottom of the
screen to select what you want to do. When the view opens, slide the
items across the view until you are done.
I'll quote Mattt Thompson:
This is the type of thing TextKit was created for. Check out Wenderlich's tutorial for an easy start.
I followed the advice in Jason's comment and it works like a charm:
Try using a UIWebView and embedded HTML for your content. – Jason Oct
30 at 19:23
Thanks Jason !!
I have a toolbar at the bottom of my screen. I want to have two buttons on it, one on the left side, and one on the right. However, unlike a navigation bar, there are multiple spots that aren't on each far side of the bar, but rather they stack next to each other from the left to right.
I tried using a fixed separator, however the length doesn't stay contant (the button needs to stay on the far left while another is on the far right) as orientation and device changes. So, how would I go about keeping the buttons on each side of the toolbar no matter the orientation and device? I feel like there has to be an easier way than getting the device type and orientation and varying the length for each one.
I tried my best to explain, and I can understand if there was an issue understanding what I'm trying to say. If you need any clarification or other details, just ask!
Thanks
Jake
There are two separators, a fixed separator and a flexible separator. You used the wrong one; use the flexible separator!