Tools: xCode, Objective-C, Mac, Cocoa
Purpose: I am creating a collection view with many buttons.
Each button opens a file in a folder and each of them has a background picture of the file (for example: jpeg file) so it looks like what you would see in a folder.
Question: How to make each button have a different image? Also, is this too difficult for a beginner?
P.S. : If i did this without the collectionview option, I would just drag the button on xib and change their background images, however I need my window to be collapsable and scrollable, hence I am using the collection view.
I would very much appreciate any comments/help/answers. Thanks!
This should not be difficult. A CollectionView holds a collection of CollectionViewItems. Inside the Item you can create any views you need. One of them could be an NSImageView that you set at runtime to the image you like. I suggest to play around with CollectionView and some f the samples Apple provides on it.
Related
I have seen this in other programs and am trying to replicate it.
I have an image on one of my forms that someone can drag-and-drop an image into. I would like to allow the user to click on that image to pop up another dialog that they could instead select a "stock" image if they choose to.
I don't see an outlet I can use for the click and putting a transparent button over the top would defeat my ability to drag and drop an image on to it.
I realize I could just change the image to a button instead but I prefer to use an image if possible.
How can I make an image clickable?
This is OSX by the way, not IOS.
Quoting from another question:
By default, NSImageView doesn't react to -mouseDown:, or -mouseUp: like other NSControl subclasses (namely NSButton) do.
The solution is given in an answer elsewhere - subclass NSImageView and appropriately handle the click event (as linked).
Drag in the standard NSButton.
Uncheck the Bordered checkbox.
Clear the Title text.
Set the Image (and optionally, the alternate image).
Also, if you are using layout constraints to set button size to image view size, don't forget to set vertical hugging/compression resistance priorities to low values (say 1).
I'm making a document viewer in Objective-C, I want to have a bar at the top of the page with a bunch of buttons in it which open up menus, change pages, etc. At the moment I'm using a custom view which then just has all of the buttons inside it, but my problem is that it isn't a static vertical height, so when the window resizes it changes the size of the custom view rather than my PDFView. Is there a way I can stop it from resizing, or is there a better method I should be using to create a menu?
Thanks!
With auto layout, you can just give the view a fixed height -- from the editor menu, choose Pin, then Height. Make sure that it then only has one vertical constraint, either to the top, bottom, or centerY.
Are you using Auto-layout ? You may have to play with it.
Without seeing the code it's hard to debug the problem. Post the snippet where you're re-sizing the views if you're not using auto-layout.
The question may be similar with
Designing inside a scrollview in xcode 4.2 with storyboards
but none of the answer there makes sense at all.
Okay I created a new controller and I added a scrollView.
The very first thing I noticed is there is NOWHERE to specify the content size of the scrollView.
Not in attributes inspector, not in size inspector.
Then what?
I am expecting some larger than normal box where I can draw all the view I want to put in. There is no such thing either.
I am very frustated.
All the "tutorial" out there tell about how to fill scrollView using code.
Another thing I tried is to select controller go to size inspector and then choose FREEFORM.
Great. I still can't make that template big.
Should I do this in XIB instead? At least on that one I can have one huge UIView. Or what is the official way industry standard way of doing this? Is there a WWDC for this one?
Say I want to draw something like these:
I don't think you can get a tutorial on this as it is simply impossible in IB. As most people already commented out what you want to do here need to be done programmatically.
If you are using XIB you can set up all your content there. Under the size tab (in the inspector) you will need to change the height to fill all your content but you still need to set up your contentSize programmatically.
For storyboard I don't think it is possible to change the size of your scrollview in IB.
I've seen this toolbar-like UI element in a couple of apps, and I'd like to know if there's a standard Cocoa object for such an element.
Xcode:
ColorSchemer:
CornerStone:
If a standard Cocoa implementation does not exist, can anyone suggest a good open-source library?
In the second example, the buttons are what Interface Builder calls "Gradient Buttons" which have that appearance without needing a background image. The buttons are just butted up next to one another.
In the other examples, the "toolbar" is just an ordinary NSView with a custom image background, with standard NSButton objects as subviews. The buttons have their border disabled so all you see is the icon.
To get the "inset" look for the icons, the button images are most likely template images. To make an image a template image, it must consist of black and clear colors only, with an alpha channel. You then call [image setTemplate:YES] on the NSImage object.
Apple supplies some pre-canned template images which you can access by using the +imageNamed: method of NSImage.
In the case of Xcode, it's a private class called IDENavigatorFilterControlBar, with this inheritance hierarchy:
IDENavigatorFilterControlBar
IDEFilterControlBar
DVTBorderedView
DVTAutoLayoutView
NSView
DVT is the prefix used by the private Developer Tools framework.
Not sure if this is what you want, but have you tried Matt Gemmell's MGScopeBar?
I am new to Mac development.
I want to add three controls in a single Scrollable NSScrollView.
1) NSTextView.
2) NSMatrix.
3) NSTextView.
Please note that text in nstextview can be of dynamic height.... and there should be no scroll for textviews.
here is a screenshot of what I am looking for -
how can I add these three views in nsscrollview? Please help!
Update 1 - can I add these controls in a NSView?
I'll assume you've got a project in Xcode 4 started. Select your project's MainMenu.xib file to begin editing your main user interface.
Start with a window. Drag a custom view into it. Add your text view to the custom view, followed by the matrix, followed by another text view, sizing the views as you go. It's at this point that you also can configure your text views not to display scroll bars. Next, select the custom view. Embed it in a scroll view, and there you are.
The window, custom view, text views, and matrix are selected from Xcode 4's Object Library palette. To embed, choose the Embed/Scroll View command from the Editor menu.
As for the dynamic sizing, you'll have to code for changing the heights of the text views, and so the height of the enclosing custom view. (That is an exercise I leave to you.) Your burden can be lessened somewhat by taking advantage of autosizing to maintain the proper spacing between the three UI elements; you can do this either in Xcode 4, or you can do it using NSView's relevant instance methods.
Good luck to you in your endeavors.