When my UITextField becomes first responder(on edit) the text is moving down very slightly and the spacing between the characters is increased very slightly. Upon resign first responder(keyboard goes away), the characters move back to the original positioning. At first I thought this was a font issue, as I am using a custom font, but the same thing happens when I use the system font or other custom fonts.
Please check the images below. The first one is with the keyboard down and the second is with the keyboard up. It may be difficult to see, as the variance is small, but the keyboard up state shows the characters moved down and apart slightly.
In xib, set textfield's borderStyle to any value than TextBorderStyleNone . And in code, set textfield's borderStyle as TextBorderStyleNone explicitly.
I could'n figure out why but it seems like initializer bug. It works fine in other code which doesn't initialize UITextField by outlet from xib.
When set textfield's borderStyle as TextBorderStyleNone at xib, the problem still remains even if set borderStyle as TextBorderStyleNone in code. It may be followed by some kind of 'layoutIfNeeded' stuff, which triggered by value change.
Selecting the "adjust to fit" property sets the property adjustsFontSizeToWidth in UITextField.
That has this property (UITextField Apple Documentation):
Normally, the text field’s content is drawn with the font you specify in the font property. If this property is set to YES, however,
and the contents in the text property exceed the text field’s bounding
rectangle, the receiver starts reducing the font size until the string
fits or the minimum font size is reached. The text is shrunk along the
baseline.
The default value for this property is NO. If you change it to YES,
you should also set an appropriate minimum font size by modifying the
minimumFontSize property.
I would try first unchecking this and seeing if that would stop it, and then follow the documentation advice and set the minimumFontSize property lower otherwise, which may also be causing the problem.
This issue could possibly be a result of the appearance of the blue "now editing" cursor. The baseline of a text (reference) is the bottom of the text. Your text is shrinking "along the baseline" by pushing down, which leans more strongly in the direction of it being a minimumFontSize/adjustsFontSizeToWidth issue.
If you are forcefully making UITextField first responder, do it in viewDidAppear: instead of viewDidLoad... This solved the problem for me...
Checking OFF the "Clip to Bounds" of textField in my storyboard works fine for me.
You have probably sized your UITextField to be slightly too small height-wise. Try manually resizing it so it's a pixel or two taller. Or select it in the XIB editor and use "Size to fit content" in the Editor menu. That ought to set the text field to the right size so that this text shifting doesn't happen.
Setting the Min Font Size property equal to the font size in Interface Builder worked for me
Changing the vertical alignment under control in the storyboard did it for me.
My issue was connected with wrong alignment of UIStackView.
When you put UITextField into UIStackView, make sure you set its alignment correctly, otherwise auto-layout won't figure out how to position your view right.
In my case, I had to set it to .leading.
stackView.alignment = .leading
You should set Font property earlier than Text property.
Related
Every time I click-and-drag a UILabel to storyboard, and then add text to Text field, the text is cut off, so I then have to click-and-drag the UILabel to stretch it big enough so that the text appears.
I can't figure out how to make the UILabel automatically get big enough to fit the text.
This would save time while designing new views.
On any element in Interface Builder you can select the element and hit...
Editor > Size to Fit Content (keyboard shortcut: CMD+=)
This will do a "sizeToFit" on the selected element. Labels will fit their text size, image view will resize to the image size, etc...
In Xcode 6.1, I had to set Content Compression Resistance Priority to a higher value, likely because I have other constraints that were conflicting, or causing the sizeToFit option to be disabled.
Before:
After:
For the text label:
Set Lines to 0
Set Height to Greater than or equal to 30 (or other value)
Now the height will be adjusted based on the lines number.
Starting with iOS 6, there's a new API, available in Interface Builder as well called 'Auto Layout'. You can specify some contraints and UIKit will resize / move your views based on those contraints. If you don't want to use Autolayout you can use the autoresizeMask property of UIViews (which is settable in Interface Builder as well).
Check out the Autolayout Guide!
To resize the views in Interface Builder as you build them, see the reply from #Fogmeister
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.
When I initialize a textlabel from a static tableview cell in viewDidLoad, everything is displayed as it should be. However when I change the textvalue some moments later after the press of a button, the text is clipped if it was bigger than the original text set in viewDidLoad. When the new text is shorter, it's being displayed correctly.
Somebody knows a solution for this problem?
-- EDIT --
Solved with:
try calling the label's setNeedsLayout method after changing the text value - that may resize the label. –
Set the adjustsFontSizeToFitWidth property of the label to YES. It will make the font smaller when text becomes longer. Also set the minimumFontSize property to a smaller value than the default.
Is there anyway of making a UILabel wrap to the next line or do I have to use a UITextView?
You would need to set the numberOfLines property to 0 and explicitly specify its dimensions, either in IB or programmatically. However, if you have a lot of text to display, I would recommend using a UITextView.
What you want is to adjust your label according to the content's size.
In iOS 6, AutoLayout will work a charm, you should set the label to have numberOfLines = 0
In a non AutoLayout scenario, you will also want to make sure the frame of your UILabel is adjusted to show the content that's on the next line.
Please check out this answer and sample code for that: https://stackoverflow.com/a/8796896/662605
I am having some trouble getting my application to properly resize the text of UILabels when the user does a swipe to delete or other type of delete. Currently, the delete button is covering up the text that is in the cell (if it is really long). I would like for them to operate like how SMS (move clipped text down a line) or iPod (delete button resizing text).
I am using a custom UITableViewCell I am working with two labels, UIImageView and a couple of subviews for backgroundView and selectedBackgroundView. I have been playing with the springs and struts of the labels in the cell and partially attained my desired effect however, the text has a weird, quick resizing bug where it becomes deformed and stretched out and then is returned proper size when the delete button is done animating.
As far as other things that I have tried, I have made sure that my text does not adjust-to-fit and I have made my minimum font size the font size that I set for the label. I have also tried over-riding layoutSubviews but that didn't seem to have any effect at all.
If a screenshot (of the deforming label) or code would be helpful, I can post both but since nothing I have done is working, I figured they would be of little value.
fixed it by setting the "mode" of the label in the view panel to "left"
It sounds like you need to set the number of lines property and the wrap property for the labels.
If your actively changing the size of the label itself, you might want to animate that change.