Disable RTL direction for UICollectionView - ios

I'm building a custom calendar view with UICollectionView. Everything is pretty well but when I tried to test when language is set to Arabic, the cells are listed from right to left. Is there a way to disable this in RTL mode.
I have checked the documentation but there is no such option.

You can disable it by setting view semantics property
You have to set it on UICollectionView
there is a property in UIView Class
semanticContentAttribute
with following value
UISemanticContentAttributeUnspecified = 0,
UISemanticContentAttributePlayback,
UISemanticContentAttributeSpatial,
UISemanticContentAttributeForceLeftToRight,
UISemanticContentAttributeForceRightToLeft

To Disable RTL on specific view in Swift 4.
myView.semanticContentAttribute = .unspecified

Related

MKMapView Legal label shows as <unlocalized>

I've added an MKMapView as a subview on one of my ViewControllers in an XIB. The map works alright in terms of showing directions. But the Legal text on the map (bottom left) shows as <unlocalized> instead of having a text saying Legal in whatever language is selected (or even English).
How do I fix this? Thanks.
Note: My app supports 6 languages if it makes a difference (but none of the XIBs are localized)
I couldn`t reproduce this but it seems like an issue in the localization file. This guy has a similar problem and resolved it by removing localization files (and creating new I think).
Of course, you can always set directly your localized string to Legal MKAttributionLabel, by getting it from MKMapView subviews, and using setValue(_:forKey:) with _innerText and _strokeText keys. But notice that this is private API :)
I can think of 2 possible solution but didn't. One is to check which subview of all your MKMapView's subviews for that specific label and add move it out of the window or scale it down to 0. The other one would be similar but by subclassing you MKMapView and try to hide this label in layoutSubviews method.

How to add accessibilitylabel for UISearchBar IOS

self.searchbar.isAccessibilityElement=YES;
self.searchbar.accessibilityLabel=#"searchbar";
self.searchbar.accessibilityHint=#"searchbar";
self.searchbar.accessibilityElementsHidden=NO;
The above code i have added for a UISearchbar outlet in ViewDidLoad.Unfortunately accessibility labels are not getting displayed.I used the above code for all UIelements and works fine except for UISearchbar.Do we have to use UIAccessibilityContainer for UISearchbar?
You need to tell iOS which accessibility trait best characterizes the object. In this case you want:
self.searchbar.accessibilityTraits = UIAccessibilityTraitSearchField;
You may also want to have a look Apple's
UIAccessibilityTraits documentation.
try to add the accessibility label to text field property of searchBar

ios 7 - Force view layout flip to RTL without language change

I have a few views in my app that need to be able to display both LTR and RTL content (not at the same time though), and it has to be unrelated to the general app layout direction. Meaning, I want to be able to tell a specific view to flip its layout from LTR to RTL and vice versa, on the fly, without changing the system language.
I researched this quite a bit, but aside of the following two solutions, it seems like it's not possible:
Flip layout on iPhone for RTL languages
How to force "Respect Language Direction" from RTL to LTR and vice versa
The first solution is not relevant in my case. The second solution gave me the idea to just keep two versions for every view, one for RTL and one for LTR, and use the relevant one on the fly. That means I'm going to have to update twice the views on every UI update though.
A third solution, of course, is to manually change the view's layout, programatically, according to the relevant direction, before showing the view.
So, are those my only options?
P.S: I'm talking about the layout only, not the localisation strings, as i'm handling the proper text myself.
I found it's quite easy to implement that, just:
func setRTL(_ sender: UIButton) {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
UINavigationBar.appearance().semanticContentAttribute = .forceRightToLeft
if let vc = storyboard?.instantiateViewController(withIdentifier: "root") {
UIApplication.shared.keyWindow?.rootViewController = vc
}
}
Preview:
And check out the full DEMO.
As of iOS 9, you are now able to do this on a per-view basis using UIView's semanticContentAttribute property. If you are using Auto Layout or if your controls are/inherit from UIKit, they should just do the right thing whenever this property is set.
Do note that for labels, text fields and views, you might also have to change the text alignment depending on the text you are displaying.

Swipe to switch focused accessibility element iOS

When the user has Voice Over on in certain apps, a one handed swipe to the right or the left changes the focused accessibility element and speaks it (for example, the App Store top charts view). I would like to have this in my own app (which uses a storyboard).
I can think of several ways to do this myself with a swipe gesture recognizer and a list of accessibility elements in order, but it seems like there must be a way to do this in the accessibility API. However, my research has turned up nothing.
Is this a built in feature? If so, how can I add it in my storyboard or in code?
Edit:
Per advice from one of the answer I have implemented the UIAccessibility protocol for my view.Here is the code.
- (NSInteger)accessibilityElementCount{
return 4;
}
- (id)accessibilityElementAtIndex:(NSInteger)index{
return [#[self.menuButton, self.firstButton, self.secondButton, self.thirdButton] objectAtIndex:index];
}
- (NSInteger)indexOfAccessibilityElement:(id)element{
return [#[self.menuButton, self.firstButton, self.secondButton, self.thirdButton] indexOfObject:element];
}
The view I am having this issue with is defined in an interface builder storyboard. As you can no doubt infer from the code, it has 3 buttons as subviews.
What you are describing is the built-in behavior for VoiceOver and can't be changed on a per-app basis.
If you want to modify the order elements are focused, look at the UIAccessibilityContainer protocol for iOS 7 or accessibilityElements property of NSObject for iOS 8. If you don't want to implement either of those, you can also simply set accessibilityElementsHidden to YES for elements you want VoiceOver to ignore.
I have fixed the problem by adding accessibility labels to the buttons in the storyboard. Because voice over already spoke their label correctly, I had not bothered to do so before.

Xcode custom control via storyboard

I want to use a custom control in my project, specifically a horizontal picker view I found on cocoacontrols.com (http://cocoacontrols.com/platforms/ios/controls/cppickerview). I've been able to include it into my project, load data and it works very nicely.
The pickerView is setted up programatically on viewDidLoad but I'd really like to be able to use it via storyboards because I'm a using static tableView. I tried to add a UIView, set the class to the PickerView class and then set up the outlet. I builds without errors or warnings but the picker view does not appear. It only shows a white rectangle.
Anyone with experience in this? Is it possible at all or should I keep it programatically?
Thanks in advance!
Well, that's normal. CPPickerView does not seem to implement initWithCoder:... I only see an initWithFrame: in the source code, which obviously means you can only instantiate that custom UIView from code. Or you can change CPPickerView's implementation to support what you want. It's open source.

Resources