Right aligned UITextField spacebar does not advance cursor in iOS 7
It would be a bit of a hack, but if you really need that to look the iOS6 way, you can replace space with non-breaking space as it's written. It's treated differently. Example code could look like this:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// only when adding on the end of textfield && it's a space
if (range.location == textField.text.length && [string isEqualToString:@" "]) {
// ignore replacement string and add your own
textField.text = [textField.text stringByAppendingString:@"\u00a0"];
return NO;
}
// for all other cases, proceed with replacement
return YES;
}
In case it's not clear, textField:shouldChangeCharactersInRange:replacementString:
is a UITextFieldDelegate
protocol method, so in your example, the above method would be in the viewcontroller designated by [textField setDelegate:self]
.
If you want your regular spaces back, you will obviously also need to remember to convert the text back by replacing occurrences of @"\u00a0"
with @" "
when getting the string out of the textfield.
UITextField Right Alignment iOS 7
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location == textField.text.length && [string isEqualToString:@" "]) {
// ignore replacement string and add your own
textField.text = [textField.text stringByAppendingString:@"\u00a0"];
return NO;
}
// for all other cases, proceed with replacement
return YES;
}
To remove the code from text
self.txtFirstName.text = [self.txtFirstName.text stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "];
FROM this stackoverflow answer - Right aligned UITextField spacebar does not advance cursor in iOS 7
Space at end of text not visible in right-aligned UITextField
Seems like triazotan has a solution involving replacing non breaking space for space https://stackoverflow.com/a/20129483/1247248
rednaw has some potentially better version, but someone was complaining of weird side effects
https://stackoverflow.com/a/22512184/1247248
I ended up going with the version of this solution suggested by meaning-matters https://stackoverflow.com/a/22211018/1247248 and that worked for me.
EDIT
It looked like a good fix but I found a problem. When you select inside the text and type the cursor jumps to the end of the line. Turns out I should have gone with triazotan's version
https://stackoverflow.com/a/20129483/1247248
Rightalignment UITextfield's cursor go left after enter a space
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
// only when adding on the end of textfield && it's a space
if (range.location == textField.text.length && [string isEqualToString:@" "]) {
// ignore replacement string and add your own
textField.text = [textField.text stringByAppendingString:@"\u00a0"];
return NO;
}
// for all other cases, proceed with replacement
return YES;
}
In case it's not clear, textField:shouldChangeCharactersInRange:replacementString: is a UITextFieldDelegate protocol method, so in your example, the above method would be in the viewcontroller designated by [textField setDelegate:self].
If you want your regular spaces back, you will obviously also need to remember to convert the text back by replacing occurrences of @"\u00a0" with @" " when getting the string out of the textfield
For Ref: Right aligned UITextField spacebar does not advance cursor in iOS 7
iOS - UITextField - No cursor when editing text
I think your cursor color is similar to text background color
you can change by this
OBj-C [[UITextField appearance] setTintColor:[UIColor blackColor]];
Swift UITextField.appearance().tintColor = .black
Related Topics
Nsstring Containsstring Crashes
Perform Push Segue After an Unwind Segue
Nslocalizedstring Only Retrieves the Key, Not the Value in Localizable.Strings (Ios)
Xcode 7 How to Refresh Provisioning Profiles
Memory Leak with Large Core Data Batch Insert in Swift
iOS Tab Bar Icons Keep Getting Larger
Get Search Bar in Navigation Bar in Swift
iOS App Crashes, Xcode Says 'Lost Connection to X's Iphone' When Debugging
How to Animate a Uibutton Between Two Png Images
iOS Get Heart Rate from Apple Watch in Near Real Time
Programmatically Get Path to Application Support Folder
Can't Install Watchkit App on Apple Watch
Change Size of Uibarbuttonitem (Image) in Swift 3
Xcode6 Error: "No Matching Provisioning Profiles Found for Application"
How to Find the Purple Port for the Front Most Application in iOS 5 and Above
Facebooksdk and Bolts Conflicting Each Other (Duplicate Symbols) on Build