rounded button image - scaling doesn't looks good - xcode

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.

Related

Resizing image to fit Ui Image View in xcode storyboard

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:

How to override UIImageView's image property in an IBDesignable subclass?

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.

How can i do a fill animation in Xamarin.Forms

I need to fill up an polygon with Xamarin.Forms. Imagine a square and fill it with some color with animation.
The easiest thing you can do is to use a BoxView view with Opacity set to zero and Color set to your desired color. Then do the animation with yourBoxView.FadeTo or yourBoxView.TranslateTo method.
If you need a border you have to make a custom render for a ContentView with border support and then put your BoxView inside it or you can use FrameView (rounded corners). http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/
This does something very similar: https://www.youtube.com/watch?feature=player_embedded&v=55r1wHdOLBo

iPhoto like NSButton

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.

Button with gradient like tint color for segmented control

I should to reproduce this behavior
I've tried using NSGradient with a simple linear gradient in order to fill it but it's a poor result. What kind of gradient is it?
Are you putting the button in a UINavigationBar or a toolbar?
UIBarButtonItem will do that shading on its own, but it tends to live in a toolbar or navbar.

Resources