UIButton not Changing Length in Different Language - swift

I have developed an iOS app that I have localized in both French and English. I have a UIButton in my UINavigationBar that reads Back in English and Retournerin French. My UIButton seems to just take the length from the English button as default so when the app is opened on a French device the text doesn't fit in the button.
I've tried having the UIButton read Retourner in my Storyboard and I can't seem to set a constraint for the length. Am I missing something?

Try this then
button.titleLabel?.adjustsFontSizeToFitWidth = true
Found in: How to adjust font size of text in a UIButton to fit the width programmatically in Swift?

Well it turns out theres a provided method for this!
I just set:
backButton.sizeToFit()
In my viewDidLoad and it worked like a charm.

Related

Swift: how to change the text of buttons in UIImagePickerController?

Could you please explain how to change the text of "Use Photo" and "Retake" buttons in image picker using Swift? I need to substitute them with an italian translation. I have found something in Objective-C but I don't know that language and I am not even sure it was for my case... Thank you
you need to make a UIImagePickerView as overlay view.
you can follow this solution
Change UIImagePicker Buttons

UITextView don't show text

I have a TextView in my xib file.
After I assign text for it, it doesn't show the text till I double click it, and actually change the selection of the text:
Before double click:
After double click:
After changing selection size:
Do you have any idea, how to show text from the beginning?
Thanks
We found the solution. This situation happens, when you try to update the txt before the view is visible.
We override the function viewDidAppear, and did this code:
// To fix the bug of not showing text in textView
self.txtViewShowDetails.text = nil;
self.txtViewShowDetails.text = self.mediaItem.mediaDescription;
[self.txtViewShowDetails setContentOffset:CGPointZero];
If the view is animated, or inside animated controlView, we have to call the viewDidAppear after animation finished.
I had a similar bug, but it happened when I made the text unselectable. Once I made it selectable again(checked in nib), it fixed the text again. While this isn't a solution to this bug (unless making it unselectable also fixes your problem), hopefully it will help others.
think you have set TextView custom font in IB .so you need to set custom font in code.Please set system font in IB and check in both device
TextView.font=[UIFont fontWithName:#"HelveticaNeue-Medium" size:17.0];
In my case text was long and it was trimming from end. I was setting text first then font and colour. I Set font first then text. It works for me.

Default UIKeyboardType for iPad for UISearchBar

I have a hidden button that brings up a UIKeyboard for a UISearchBar by making the UISearchBar the first responder. I've tried changing the keyboardtype to different keyboards like so:
self.SearchBar.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
but I continue to get the same keyboard on default with the letters first. Is there a way to default on the numbers since I only need numbers for the iPad? Thanks.
It seems like the answer is that keyboardType must be set when the searachBar is created like in viewDidLoad for example to take effect.

iPhone keyboard with a UITextView

I feel that this question has been asked 10^78 times, but for some reason, am unable to find the question, nor the answer ..
I want to add a keyboard with a uitextView at the top .. Exactly like the default SMS application on the iPhone ..
How can I do that?
*Bonus: if you can also give me a hint as to how to animate it with the keyboard (goes down when the keyboard animates out .. and goes up with the keyboard);
You need to use a UIToolbar (containing your text views, etc.) and set the inputAccessoryView property of the UITextView to that toolbar. The animation should take place without any additional code.
See http://www.randomsequence.com/articles/adding-a-toolbar-with-next-previous-above-uitextfield-keyboard-iphone/

UITextField placeholder text position wrong when right aligned and orientation changed

I'm not sure if I've found a bug or missing some intricate setting in the iOS SDK.
I have a UITextField with right aligned text and some placeholder text. I've set it to autosize when switching from portrait to landscape (IB settings are like this: http://db.tt/laTmXIS ).
When in Portrait, it all works as expected: http://db.tt/skf8wqN However, after rotating the placeholder text is in the wrong place: http://db.tt/7pU5kdR
It looks to me that the autoresizing properties are not replicated into the placeholder text UILabel subview.
I've replicated this in a new project (download here: http://db.tt/OSnvv2Y), so it's nothing funky in my code as far as I can see.
Any ideas?
Update: Dan's workaround fixes this. Add an IBOutlet connected to your textField and then add this code to your UIViewController...
- (void)didRotateFromInterfaceOrientation:
(UIInterfaceOrientation)fromInterfaceOrientation {
textField.textAlignment = UITextAlignmentLeft;
textField.textAlignment = UITextAlignmentRight;
}
i set it to left and then center in same function upon rotation, that seems to fix it until they fix the bug! :)
This appears to be a bug in UIKit. Please file a bug report, including this sample project and images. It'd be nice if the sample app worked for both iPhone and iPad.
I agree that the text should stay flush with the right edge of the textfield.