UITableViewCell Subclass, Editing Mode problems UILabel resizing when scrolling - objective-c

I have a UITableViewCell subclass (set up in IB). When entering editing mode, the autoresizing masks do their job and resize some UILabels. But when a cell scrolls out of screen, the UILabel seems to resize itself and the text then runs off the screen. Even when ending editing mode, the text doesn't resize back to normal. What can I do to prevent this?
Edit: I should also mentioned, my autoresizing masks for the UILabel are Content Mode Left and Flexible Width. Again, they seem to do their job when first entering editing mode.

I was able to fix it by manually resizing the UILabel in cellForRowAtIndexPath like so:
if (tableView.editing) {
cell.previewLabel.frame = CGRectMake(previewFrame.origin.x,
previewFrame.origin.y,
217,
previewFrame.size.height);
} else {
cell.previewLabel.frame = CGRectMake(previewFrame.origin.x,
previewFrame.origin.y,
237,
previewFrame.size.height);
}
Still, this is kind of ugly to me, so I'll gladly accept a better solution.

Related

UIView in UITableView disappear when becomes firstResponder

In storyboard I have a UITableViewController-->UITableView-->UITableViewSecion--> with static cells
in the same UITableView I also have a UIView that holds a background image and UITextView.
A click on a button shows the UIView and set it's frame, which appears OK, but as soon as I click on the UITextView or make it firstResponder programmatically the keyboard appears and the view disappears
the code when clicking the button
self.myView.frame = CGRectMake(0, self.tableView.contentOffset.y+100, self.tableView.frame.size.width, self.tableView.frame.size.height-100);
self.myView.hidden = NO;
how can I fix this?
Can you copy paste us the code where you add the view to the tableview? Are you doing it with constraints or with frames?
The issue you are having is probably due to the fact the UITableViewControllers automatically shrink the contentSize of the UITableView they hold when the keyboard shows. If you add a UIView to your tableView with addSubview: programmatically, you might need to add a flexible bottom resize mask to make sure when the contentSize shrinks in height, your view stays attached to the top and not the bottom.
Try this on viewDidLoad:
[theViewYouAddedToTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];

When NSTableview Load second time its customcell Subview's change it's position how to solve

I am new for cocoa OSX application might be this question is simple but i try my best to find out this issue and at the end i asking question here.
I am creating NSWindowViewController and in side it i Used NSTableview with Customcell. In customeCell i used NSView (customView) and all Cell IBOutlet put in side NSView. When First time that NSWindowViewController load that show fine but after close the window and again i open it. its NSTextField IBOutlet change its position top to bottom of the cell.
I try to find this some property change but did not fix it i attach its screen example what was happen with my cocoa osx Application.
I notice that this happen when i used following code for setting NSview's background color from property Inspector i setting NSView Core animation like.
And set background color in viewForTableColumn like:
cellView.bgview.layer.backgroundColor = [NSColor whiteColor].CGColor;
Color set properly and all working fine when i reload table view that top label going to bottom and that will display revers UI order for cell as i show in my question.
And i tested with if i remove NSView setting background color code as i mention above then working perfect no re-order and all things. I am not using Auto-layout.
So after then i create custom subclass of NSview for setting color like following:
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
// Drawing code here.
}
I remove my old code and use this one for setting background by creating NSView subclass and my issue fix.

UITextView in UIView not resizing

I have an UIView named _containerView and inside this UIView I have a custom UITextView named _codeTextView. When the app is loaded, these views occupies the whole screen, however, when the keyboard appears, I would like the screens to resize.
I have to following method when the keyboard appears:
- (void)keyboardAppears:(NSNotification *)notification
{
_containerView.frame = CGRectMake(0, 0, 320, 216.0f);
_codeTextView.frame = CGRectMake(0, 30, 290, 216.0f);
}
The containerView gets resized properly however, the _codeTextView in it does not resize and I really have no clue why it's not resizing. I've already tried changing various options and it's driving me crazy :(
Could anyone help me?
Thanks in advance!
I just created a project with the scenario you described. setFrame worked for all views with Autolayout disabled, but not with Autolayout enabled.
Do you have Autolayout enabled for that View Controller? setFrame does not work well with autolayout.
You'll have to use constraints to programmatically adjust your views.
(answer from: Can I use setFrame and autolayout on the same view?)
You can find some help here: http://nszombie.com/2010/12/08/ConstraintBasedLayout.html

Keep subviews not transformed during UIScrollView zooming

I have UIScrollView with content view that has a lot of different subviews (including some labels) on it. During zooming of content view all these different subviews are zoomed as anticipated. However I would like text of UILabel subviews not changed.
I tried next:
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
// ...
UILabel* label = (UILabel*)[scrollView viewWithTag:labelTag];
[label setTransform:CGAffineTransformMakeScale(1/scrollView.zoomScale, 1/scrollView.zoomScale)];
}
Though the resulted text looks ugly (especially when scale factor quite big), even if I call [label setContentScaleFactor:scaleFactor] during scrollViewDidEndZooming:.
What are possibilities to solve that?
Put the uilabel outside the scroll view.
That would solve your problem. Everything would zoom apart from the label.

Resizable UILabel which scrolls across the screen

Right, I'm trying to get a label with text in it (done already obviously), which scrolls across the screen.
The text that is input into the label is done by a UITextField and a UIButton. This updates fine.
But I'm trying to get the UILabel to resize accordingly to the amount of text input, so that the WHOLE lot of text scrolls across the screen.
This is the code I have at the moment for the scrolling label:
[lblMessage setText: txtEnter.text];
CABasicAnimation *scrollText;
scrollText=[CABasicAnimation animationWithKeyPath:#"position.x"];
scrollText.duration = 3.0;
scrollText.repeatCount = 10000;
scrollText.autoreverses = NO;
scrollText.fromValue = [NSNumber numberWithFloat:500];
scrollText.toValue = [NSNumber numberWithFloat:-120.0];
[[lblMessage layer] addAnimation:scrollText forKey:#"scrollTextKey"];
The problem is, sometimes is starts scrolling in the middle of the screen, and sometimes vanishes before it has fully gone acrosss.
It also cuts of text due to the label being one size.. I don't know how to change this.
Thanks in advance.
Dom
I believe something similar to the solution for this question would work for this case.
You could embed the UILabel in a UIScrollView, with the UIScrollView set to the max size of the label that you want to display on the screen at one time. The UIScrollView would need to have its scroll indicators turned off using its showsHorizontalScrollIndicator and showsVerticalScrollIndicator properties. On a change of text, you could do the following:
[lblMessage setText: txtEnter.text];
[lblMessage sizeToFit];
scrollView.contentSize = lblMessage.frame.size;
followed by the panning animation code as described in the above-linked question, with the frame to be panned to being the far right of the UILabel. This would cause the text to scroll at a constant rate across the label. If you want the label to scroll back to the beginning, you could use the UIView setAnimationRepeatAutoreverses: and setAnimationRepeatCount: methods in the beginning of your animation block.
The label resize worked great thanks!
Now, i've put the label into the scrollview and i've got that showing up.. but I'm now not sure of the exact animations to add to that. I tried some of the ones on the link you gave me, but they're not working.
EDIT: Nevermind, I've got it all working now.
CGPointMake(x, x) is what i needed for the contentOffset.