How can I create a iPhoto like button like in the picture
I've tried out several things using round textured buttons or setting the button's image as template. But none of these approaches really works.
Thanks so far for your answers.
EDIT:
The image of the button should just be a simple pdf. The gradient and the white shadow should be drawn automatically.
As Justin mentioned you should create an NSButton with type Momentary Change. You should then indicate that it is a template image by including the suffix Template in the filename, e.g. EditTemplate.png.
I know you said you tried setting the image as template, but I found that this wasn't always effective if I wasn't using the Momentary Change button type.
You could subclass NSButtonCell. And implement these functions:
- (void)drawImage:(NSImage*)image
withFrame:(NSRect)frame
inView:(NSView*)controlView
{
// Draw the image of the pen.
}
- (NSRect)drawTitle:(NSAttributedString*)title
withFrame:(NSRect)frame
inView:(NSView*)controlView
{
// Draw the text.
}
- (void)drawBezelWithFrame:(NSRect)frame
inView:(NSView *)controlView
{
}
To setup the subclass just edit the "Custom Class" field of the Button Cell in Interface Builder from "NSButtonCell" to "YourSubClass"
I think the simplest solution is to create button with type: Momentary Change and add on it image with transparent background with .png type of file and when button is ON You can change to other picture with background.
For example to set/change image:
[_yourButton setImage:_image];
If I have understood correctly what You want to do.
Related
I am trying to fit an image to fit the entire of the Ui Image View. I want to do this because I want to round my image and it does not work because the image is smaller than the entire view. So rounding it rounds the outside of the image and is not visible. I have tried to add constraints but that does not seem to have workout.
Here is an image of what I am trying to do:
https://i.stack.imgur.com/mIGow.png
The problem images:
https://i.stack.imgur.com/LGDyx.png
https://i.stack.imgur.com/K3RVZ.png
OK - the problem is that you don't understand the Xcode interface.
When you have added a UIImageView, set its image, and then select it, you see this:
If you click the image view again, Xcode shows an additional "highlight" outline:
That has nothing to do with how it will look when you run your app.
Regarding the screen-cap from the video you are watching... You either didn't notice, or forgot, two things:
it's a tutorial for SwiftUI - the screen-caps you've posted for what you're trying to do is from a UIKit based app.
at 17:20 of Part 1 of that series, the author explains how he is setting the corner radius.
To get what you want with UIKit, you need to write some code to give the image view rounded corners. To have it show up at design-time, you need to use an #IBDesignable image view subclass.
Here's a very basic example:
#IBDesignable
class RoundedImageView: UIImageView {
override func layoutSubviews() {
layer.cornerRadius = 20
}
}
If you set the Custom Class of your image view to RoundedImageView, and then either select either Editor -> Refresh All Views or have Editor -> Automatically Refresh Designable Views checked, you'll see this:
I have an image of a button with rounded corners.
When I resize it (using auto-layouts) it doesn't looks so good.
If I'm trying to slice it (via xcode assets) it's shape looks better, but since the button image has some types of green, the slicing not working so good (you can see color differences when it's sliced).
Any other solution to be done here?
You can create a custom button class with rounded corners
class GameButton: UIButton
Then in layoutSubviews
override func layoutSubviews() {
self.layer.cornerRadius = 5
}
Try to set the CornerRadius to button layer and use that image. That could do better. Don't resize the image.
I made a subclass of UIImageView which uses Core Graphics to generate a new image that is cropped to a circle with an optional border. It works fine when I run the app. In Interface Builder, however, the generated image renders properly, but it does so underneath the "no image set" placeholder for a UIImageView. Also, the image property shows up twice in IB, and the new image is only generated if I set the overridden field. If I set the image in the regular UIImageView field, it just acts as though it isn't subclassed. Is this just a bug in IB, or is there a fix?
#IBInspectable override var image : UIImage? {
didSet {
// Make the image a circle
makeCircleImage()
}
}
We are stuck with Apple's IB implementation, I'm afraid. I recommend that you find a workaround to overriding image. You can instead implement prepareForInterfaceBuilder and awakeFromNib and do it there, or have a method of doing this operation once in the draw or layout methods, or have a boolean IBInspectable var that does this operation when set.
I want to implement an animation which is like the sync animation of evernote app on Max OS X.
The button looks like:
When the animation runs, only is the white arrow rotating.
I tried to use Core Animation, and the steps are following:
1 I dragged a NSButton to the tool bar and set it to an outlet aBtn. I set the blue blackground image to the aBtn.
2 I created a CALayer instance variable aLayer and add it to the aBtn. So it can look like the button above.
3 when aBtn was clicked, I add the rotation animation the aLayer. It run perfectly well.
The problem is when I want to customize the tool bar, the aBtn shown in the tool bar palette didn't have the aLayer and only had the blue background image.
Then I tried to find the event or notification for the showing or closing of the tool bar palette. As a result I can reset the image of the aBtn before the tool bar palette was shown or hidden.However, I couldn't be notified when the tool bar palette was closed.
Could any one give any suggestion?
If you have good idea about how to implement this animation, please let me know.
Thanks!
I create a gif to store the animation, and create an NSImageView for the gif. Then I use -[NSToolBarItem setView:].
Using gif is an easier way than implementing it with Core Animation.
I'd like to make an icon for my NSToolbar that has the same system stylings applied to it as the template icons in IB. How do you do this? I can't get the toolbar to apply system stylings like it says it will in the HIG.
Thanks!
In Mac OS X v10.5 or later, images whose name ends in the word "Template" are automatically marked as template images. NSImage Class Reference
NSImage *image = [NSImage imageNamed:#"MyImageTemplate"];
This also works for Interface Builder.
More information: http://www.proppe.org/blog/2007/12/01/nsimage-templates/
If you mean for a monochromatic icon, make sure you set it as a template image. That's what tells the system to render it with the inner gray or blue gradient.
The toolbar doesn't do that automatically. You have to create the graphics yourself. The Lion-style icons are usually mid-gray with a subtle inner shadow and a 1px whitish drop shadow. Here's an example done in Photoshop:
And here's all the layer styling done to it:
The specific numbers and colors may vary depending on the icon's shape and size.
On a side note, the HIG was saying that icons may change depending on the control. For example, when you disable a button, its icon will be displayed semi-transparently.