Two UIImage in one collectionview cell? - uiimage

I want to put second UIImage inside collectionview cell but it return error
"error: Illegal Configuration: The newIcon outlet from the DashboardViewController to the UIImageView is invalid. Outlets cannot be connected to repeating content.
"
Here is the picture to describe error that is generated :
How to make two UIImage inside one collectionview cell?

You'll need to add a new UIView into "dashboardCell". Once you've added a UIView you can then add more UIImages to that UIView.

Related

Autolayout not working properly

I have UIView in separate .xib file and I make UICollectionView in it.
To add collectionViewCell I made separate .xib file.
Now below collectionview I want to add UIView.but my problem is I set height of collectionview dynamically by using code.
But when I add this using autolayout constraint to add view below bottom of the collectionview but view will add on distance where It put on UI.
I want that first setup collectionview than view placed below it.
Problem screenshot 1
Below UIView constraint I have already set 2
Thanks
Nirav Zalavadia
Instead of adding the UIView below the UICollectionView, place the UIView in the bottom of the screen.
Then, use a constraint from the bottom of the UICollection view to the top of the UIView.

Getting the preferred size of an NSCollectionView

I'd like to center an NSCollectionView in its enclosing scroll view (horizontally & vertically).
How can I determine the ideal size of the collection view so that all item views fit?
It appears that a collection view will always resize itself to fill the entire document view when enclosed in a scroll view.
Also, if not enclosed in a scroll view, the collection view won't change its frame when new items are added.
I would suggest you to customise the NSCollection View. All you can do is override "drawRect" Method of NSCollectionView and inset its own rect. Below is what will fix your issue
Steps to implement:
Create a Class "NSModifiedCollectionView" Where it inherits from NSCollection View and do the following.
#interface NSModifiedCollectionView : NSCollectionView
#end
#implementation NSModifiedCollectionView
- (void) drawRect:(NSRect)dirtyRect
{
//You can inset more than 9.0 as per your needs but this will make you fit exactly
NSRect insetRec = NSInsetRect(dirtyRect, 9.0, 9.0);
[super drawRect:insetRec];}
2: Drag and Drop a NSCollectionView from you object list to the Xib and modify its custom class to "NSModifiedCollectionView". Now Run and check it should work as you expect.

nssplitview programmatically add nsview on top

I am trying to programmatically add a NSView over a NSSplitView (to cover it). Every attempt to do this has resulted in it being added into the NSSplitview as an extra subview.
Can anyone please help?
Codes:
InfoTrainView *myView = [[[InfoTrainView alloc] initWithFrame: aFrame] autorelease];
[NSBundle loadNibNamed:#"InfoTrainView" owner:myView];
[self.windowController.splitViewBase addSubview:myView];
I believe you need to add your new view as a child to the NSSplitView's superview (ie. parent). This way it becomes a sibling to the NSSplitView and can cover it. Your current method makes the new view a child of the split view, which then sets itself up as splitting four ways.
NSView* parentView = [self.windowController.splitViewBase superview];
if (parentView)
[parentView addSubview:myView];
parentView above should get you the "content view" that is the default NSView inside of an NSWindow, which IB placed the NSSplitView inside. If parentView == nil, you can try manually adding an NSView to the window first, then putting your NSSplitView inside of that.
On a side note, your question answered my own question - how to programmatically add to the views split inside of an NSSplitView! Thanks :)

UIScrollView subviews and setNeedsDisplay

I've the following problem :
I have a UIView containing a UIScrollView as a subview. (nib file).
Programmatically I add several subviews (UIImageView) to the UIScrollView, each UIImageview contains an image loaded from the net asynchronously, so I need to update the scrollView when the images are downloaded. In the class responsible of the images fetching, I advertise the the View controller responsible to manage the scrollView, using this code
[[(MosaicViewController *)data] scrollView setNeedsDisplay];
the Ivar data is a pointer to the ViewController.
This stuff don't work,no reload of the scrollView happen
To be sure that the call is triggered I wrote a method inside the viewController containing the scrollView, and inside this method I called setNeedsDisplay,
[(MosaicViewController *)data updateView];
-(void) updateView
{
NSLog(#"setNeedsDisplay");
[self.scrollView setNeedsDisplay];
}
the method updateView is triggered correctly, I mean is called after each Image is downloaded, but the scrollView contents isn't updated. In the ViewController containing the scrollView I don't implement the drawRect method, could be this the reason for the lack of update after calling setNeedsDisplay?
Any help/suggestion/reference etc.. is welcome
Thanks in advance
Dude are you doing imageView.image = downloadedImage ??
Also you should not have to do [self.scrollView setNeedsDisplay] since you did not change anything on scrollView !!
What changed is the content of the imageView and imageView.image = downloadedImage will automatically trigger setNeedsDisplay on imageView !!
Some other check points
Is scrollView visible?
Is scrollView.contentSize set??
Is the scrollView frame correct ??

Apple Interface Builder: adding subview to UIImageView

I created UIImageView with the help of Interface Bulder. Now I want to place label inside it (as its subview). In code I can type something like: [myUIImageView addSubview:myUILabel]; But can I do it with the help of IB? I found the solution for UIView, but can't find something similar for UIImageView.
You cannot add a subview to UIImageView in interface builder for reasons only known to Apple! You are right in saying that you can addSubview programmatically, but then, the overhead of setting autoresizing masks and placements of subviews should all be handled in code, which is cumbersome.
So there is an easy workaround. Instead of dragging an instance of UIImageView in the nib, just drag a UIView and change its class to UIImageView from UIView (cmd+4 option of inspector). The only difference you find in the nib for default imageView instance and your new UIImageView subclass instance is: you cannot set image to your new imageView from nib (cmd+1 option). So, in the -viewDidLoad method of its appropriate viewController, set image to this outlet of UIImageView.
By doing so, you are free to add subviews to your "now UIImageView" instances in interface builder, which is much easy.
I would like to add answer.
While it sucks you cannot add subview to UIImageView, you can get the same effect by incorporating UIView with transparent (clear color) background.
Then put the UIImageview BEFORE it.
So the UIView has the subviews and the UIImageview is the background of the UIView.
I think that's apple's intent.
Here is a screenshot:
Here is the result:
Don't forget to set background as clear color
Now if someone could actually point me to a tutorial how to do this it'll be great. I spent hours doing it the checked answered way. The checked answer is a fine answer but very unintuitive because you can't see your background image clearly while working. I think mine is the proper way to do so.
In latest XCode(4.5) there is an option to drag and drop the required controls to the parent.
It is quite easy.
Attached screen shot for the same. I dragged the Label/TextField and Button to UIImageView
Use this code:
UIImage *image = [UIImage imageNamed:#"background.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view insertSubview:imageView atIndex:0];
(replace background.png with image) (replace atIndex:0 with whatever place in the .index root you want to insert the image and your off.

Resources