UICollectionView in UILabel sizeToFit - uilabel

I used CustomCellClass in UICollectionView. Try this class in uilabel sizeToFit but not working.
But create the new uilabel in cellForItemAtIndexPath method, working.
How to set SizeToFit UICollectionView in CustomCellClass UILabel;
Thanks.

Pop it in the CustomCellClass layoutSubviews.

Related

Why won't this code allocate a subView?

This is my code where I'm trying to create a subView... I'm using XCode4 with StoryBoards. The app is crashing on the 2nd line where it is allocating subView with EXC_BAD_ACCESS. vFrame has valid content. What is wrong with this? (I'm using XCode4 with Storyboards, btw).
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect vFrame = CGRectMake(60,100,200,200);
subView = [[UIView alloc] initWithFrame:vFrame];
subView.backgroundColor = [UIColor redColor];
[self.view addSubview: subView];
}
UPDATE: definition for subView:
#interface PreferencesViewController : UIViewController {
UIView *subView;
}
#property (nonatomic, retain) UIView *subView;
#end
That really should work. Was your view controller (PreferencesViewController) properly alloc'd and init'd? Did you #synthesize your subview?
Although it shouldn't matter, you could try using floats for the CGRect (add a .0 to the end of each).
Try moving your sub view instantiation code to the method viewWillAppear of your main view. This guarantees everything has been initialized.
The problem was the UIViewController was farkled...don't know how, but once it was replaced, it worked like a champ! Thank you all for your responses...

NSScrollView in Cocoa

I am trying to get an NSSrollView with an NSTextField in it to work, however the scrollbars do not seem to respond to anything that I am coding.
I am declaring the NSScrollView as an IBOutlet, add it as a property and then synthesizing it. However, it's to no avail.
The scrollbars do appear when I resize, however they serve no function at the moment.
I have tried to use the apple documentation, but again, no joy there.
Any help? Thanks!
As You was saying "For my purposes, any container which scrolls will do the trick" You can use NSTextView in an NSScrollView. And for setting text You need to use setString instead setStringValue.
Example how to set text in NSTextView:
.h
IBOutlet NSTextView *textView;
.m
-(void)awakeFromNib {
NSString *string = #"my text";
[textView setString:string];
}
Don't forget IBOutlet NSTextView not NSScrollView.
NSTextView is in NSScrollView:

How to repaint UIView when text in UILabel changes?

I've a subclass of UIView with a UILabel with is added as subview to the view. In the layoutSubviews method the position and height of the UILabel is calculated. My problem is, that this height should be recalculated, when the text of the UILabel changes. The text is inserted into the label from the UIViewController, so the view does not know when this happen.
You can subclass UILabel to override setText: like this:
#implementation MyLabel
- (void)setText:(NSString *)text {
[super setText:text];
[self.superview setNeedsLayout];
}

Accessing drawRect from ViewController?

I have a UIView subclass with a drawRect method. My viewController uses this subclass (I just set it in the xib), and so UIView draws a rectangle to the screen fine.
Now, I'd like to send a bunch CGRects stored in my viewController to my UIView drawRect method.
I'm unsure how to pass them. Any ideas? Thanks.
You can add properties to your UIView subclass to store the CGRect's, set them from your UIViewController then call [self.view setNeedsDisplay]; from your UIViewController.

Displaying UItableViewController inside UIPopoverController

I am dispalying a UITableViewController inside a UIPopoverController. Everything works fine expect that the size of the TableViewController is very large even thought there are only 3-4 cells. How can I make it so the popover controller's height is exactly the same as tableview's height?
You could use UIPopoverController's method - (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated or use the property on UIViewController #property(nonatomic, readwrite) CGSize contentSizeForViewInPopover to achieve this.
Override the contentSizeForViewInPopover of your UITableViewController like this:
- (CGSize)contentSizeForViewInPopover {
// Currently no way to obtain the width dynamically before viewWillAppear.
CGFloat width = 200.0;
CGRect rect = [self.tableView rectForSection:[self.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
return (CGSize){width, height};
}