How can i get writing language of uitextview?
or
how can i know uitextview is right to left or left to right in current state?
[textView baseWritingDirectionForPosition:[textView beginningOfDocument] inDirection:UITextStorageDirectionForward] == UITextWritingDirectionRightToLeft
Should return true if the UITextView is right-to-left, and false otherwise.
Further documentation can be found here, if you need it!
In answer to your other question, you can get the keyboard language used from UITextInputMode docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInputMode_Class/Reference/Reference.html
This solution worked better for me
[NSLocale characterDirectionForLanguage:self.textView.textInputMode.primaryLanguage] == NSLocaleLanguageDirectionRightToLeft
Related
I am needing to put the tabBarController!.selectedIndex number inside a constant.
I am expecting a number between 0 and 3 depending on what tab I choose, but instead I get numbers like 2147483647
Any ideas why this is?
The code is:
let selectedTab = tabBarController!.selectedIndex
print(selectedTab)
That value is NSNotFound. In this case it seems to represent "no selection".
Thanks to Joshua's answer and Philip's comment for getting me on the right track.
The problem was that I had put the constant in my viewWillAppear method which meant it was not reading the VC that I was selecting, because it hadn't appeared yet.
The NSNotFound was therefore triggered, because the view had not loaded yet.
I need create a method which detects keyboard input language . for example when keyboard language is French does something and when is English does something else
I search on the Internet and found UITextInputMode but I don't know how to use it , I would be grateful if you help me . thanks
It's quite simple, you can do it this way:
UITextInputMode *textInput = [UITextInputMode currentInputMode];
NSString *primaryLanguage = textInput.primaryLanguage;
NSLog(#"Current text input is: %#", primaryLanguage);
As noted in Apple docs, "The value of this property is a BCP 47 language code such as “es”, “en-US”, or “fr-CA”".
If you need to be notified about changes, you add your controller as observer for UITextInputCurrentInputModeDidChangeNotification
I have implemented a UISearchBar for finding an element in UITableView. Everything seems to work fine, and now I am at the part where I need to actually perform real-time search for every key pressed in the textField, and narrow down the search with every button press.
So before I start coding, I wanted to know if there is any inbuilt library function that could help me with live search ? (string comparison) or anything ?
Your answer could save me some time.
Thanks.
It so happens that there is in fact an inbuilt function that helps with RealTime Search. Phew !
NSRange match = [userNameString rangeOfString:searchText options:NSCaseInsensitiveSearch];
// match.location will provide the exact location of a match of searchText with a String
// match.length will provide the length of match
I am new to iPhone programming so am hoping someone can help me out here. I have searched the web, but can only find information on count down timers.
What I am looking to do is start a count up timer when a button is pressed and then stop it when a certain value drops by, say 5, and finally display that time. I can display values on screen once I have them, but getting the time in the first place is proving difficult for me.
I apologize if this is a simple question, but I look forward to reading your responses.
Thanks in advance,
stu
NSDate will provide the current date. You can use - (NSTimeInterval)timeIntervalSinceNow
to get the time since the first call and now.
There's no difference between an up-counter and down-counter. Just change the order of your subtraction.
UpcounterElapsedTime = UpcounterCurrentTime - UpcounterStartTime;
DowncounterElapsedTime = DownCounterStartTime - DownCounterCurrentTime;
it is simple to set the Return key programmatically:
textField.returnKeyType = UIReturnKeyDone; // This is in the loadView/init-method
However, it seems that it is not so easy to toggle that key, i.e. change it from Done to something else depending on, for example, what is currently shown in the text field! That is, a subsequent statement in a callback method:
textField.returnKeyType = UIReturnKeyRoute;
does not change the keys title from Done to Route!?!?
Has anyone else observed this? Any workaround?
Regards,
/John
If by "does not work" you mean it doesn't do anything perhaps you need something like this?
- (BOOL)textFieldShouldReturnUITextField *)theTextField
{
[theTextField resignFirstResponder];
return YES;
}
If by "does not work" you mean that the text is wrong, as far as I know you can only select from the set of predefined buttton types that the API provides. I don't know of any way to directly set that text. There may be a way with private apis (see EricaSadun.com)