Textlabel in tableview cell doesn't resize after refresh - iphone

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.

Related

UITextfield text is moving on edit

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.

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.

iphone uitablecellview overflow

Is there a way to hide the overflow in a UITableViewCell? I have a custom cell view, that I load into the table, where some of the information is supposed to be hidden on load, and then each row will expand when clicked.
Right now, I'm returning height 30 for my row, which is the height of the cell header, but the buttons and text that are supposed to be hidden just overflows and is placed on top of the headers below.
While you can use clip subviews(cell.contentView.clipsToBounds = YES), it's probably best if you add the subviews when you need to expand and remove the subviews the cell collapses. It should increase performance.
There's a property on UIView "clips subviews?".
If you set this value TRUE for the cells, it should stop the buttons from overflowing - you can do it either in IB, or in code programmatically (slightly different name in code).
HOWEVER ... this may NOT be what you want. Depends on the effect. Last time I did what you're doing, I used clipsubviews.
Usually, the correct way to hide your buttons etc is the UIView property "hidden" (or the other one - "enabled").
But that might mess with your animations - depends how you're animating the click-to-expand.

Is it possiable to have the detailTextLabel automaticly resize the font?

I'm using the UITableViewCellStyleValue1 for my table cell style. That's the one that puts the textLabel on the left, left aligned, and the detailTextLabel on the right, right aligned.
Some of the data I'm passing to the cell, at times, is to long for the label and I get the the truncated look with the ... at the end.
I think it would look better if it would just lower the point size of the font to make it fit.
Is there a way to do this automaticly or would I have to manualing check the length and modifying the cells?
Any time you run into a limitation with Apple's default cell styles, which can be often, make your own UITableViewCell subclass and add custom views to its contentView property.

Resize UILabel text with swipe to delete

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.