Rounded Rect UIButton with outer border - swift

i wants to make outer border for UIButton.
When i click on button add border width, not inside rounded button - outside of this button.
P.S. i use this code to make button round:
button.layer.cornerRadius = 0.5 * button.frame.size.width
button.clipsToBounds = true
And this for border:
self.button.layer.borderWidth = CGFloat(10)
Now i have this result:
But i need border outside of the button. if someone help me, it's will be amazing, thanx.

Just add alpha (transparency) and instead of adding the border, change its alpha value. set the border color as follow:
let borderColor = UIColor(red: 0.0/256.0, green: 0.0/256.0, blue: 0.0/256.0, alpha: 0.0)
and modify the alpha value. This way it will look like you are adding the frame on the outside of the button.
Now, you didn't specify if you wanted the animation as well. If you do want the animation, you should just draw the frame outside the button's boundary, it might be trickier to do, and the frame would not have the button's functionality.
Another option of keeping the button and the animation is to draw a circle with behind the button and set the border to transparent, then animate.
These are only three of your options, I'm sure there are more...

Related

How can I edit the corner of a button in swift, in button editor?

On the right panel editor, there are all the characteristics from the button. But I want to know if there is an option to round the corners of the button in this panel.
right panel for Xcode
You could extend UIButton and use #IBInspectable to be able to set the corner radius more comfortably. I added some math so that the Button can be at max a circle and always looks pleasing. #IBDesignable is used that the button is able to render nicely in the Storyboard.
#IBDesignable
public class CornerRadiusButton: UIButton {
#IBInspectable
var cornerRadius: CGFloat = 0 {
didSet {
cornerRadius = (cornerRadius > 100) ? 100 : cornerRadius
let max = self.bounds.size.width * 0.5
self.layer.cornerRadius = max * cornerRadius/100
}
}
}
In recent versions of iOS a button just shows the text.
It doesn't pay attention to the corner radius. If you set the background color to something other than transparent then it gets filled with that color.
If you want a colored rounded rectangle, set the background color, and go to the identity inspector and add an entry under "user defined runtime attributes" with a key of "layer.cornerRadius" and a number value of 5.

SK subview color doesn't change to it's .backgroundColor

I am trying to make an overlaying view which just makes the screen turn red. However, even if I set the background color to any color, it just shows as gray. I can still maneuver it around the screen, I just can't change the color for some reason.
Here's what I put into my didMove to view function:
let pulseView = SKView(frame: self.view!.frame)
pulseView.backgroundColor = SKColor.red
pulseView.alpha = 1
self.view?.addSubview(pulseView)

how to remove navigationbar blur effect - swift

i searched a lot on internet but did not find any solution for the problem, i don't want the navigation bar to be blur as in the screenshot
the colour of navigation bar does not match with the other colour even i have used the sam hex value for both. i want to fix it. please help
this is the code i am using to colour navigation bar
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = UIColor.white
navigationBarAppearace.barTintColor = UIColor(red: 204/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0)
What you see isn't actually blur effect, but translucent style of UINavigationBar. If you don't want translucent bar, set its isTranslucent property to false
UINavigationBar.appearance().isTranslucent = false
Use:
navigationController.navigationBar.isTranslucent = false
You can disable this blur effect by using both standard and scroll edge
By Setting
**Standard Appearance
background-color**
This setting will Work to hide the blur effect on a scroll and also to set title style on scroll
**Scroll Edge Appearance
background-color**
Appearance without scroll-like background color, title, etc.
Other Settings are remained the same like
Translucent: true etc

Swift View Animation from Line

Swift View Animation from Line
Swift 4.2, Xcode 10.0
I want to perform an animation with a view wherein it builds out or into a line.
Build out of line:
Build into line:
My only solution at this point is to put another view on the opposite side of the line to cover the view before it starts to animate. But this is a bad solution and it can sometimes block other views. Also, I would like to avoid stretching my content because I want to be able to perform this animation with images. What would be the best way to integrate this. Thank you in advance for the help!
So you want this:
A subview can extend outside the bounds of its superview. When this happens, the part of the subview that is outside the superview is visible if the superview's clipsToBounds property is false, and hidden if the superview's clipsToBounds is true.
I used this clipping to hide the part of the green view that is below the line. Perhaps these side views at the halfway point of the animation will help explain how I set it up:
The superview (labelled “hider”) has been shrunk here to half the height of the green view. With clipping enabled, half of the green view is hidden. With clipping disabled, the bottom of the green view is visible below the line.
Here is how I set up the demo:
I put the green view in a new superview. I call this new superview the “hider”.
I turned on the “Clips to Bounds” check box in the hider's Attributes inspector.
I set width and height constraints on the green view. You could use other constraints (like leading/trailing) to control its size.
I constrained the leading, trailing, and top edges of the green view to equal the corresponding edges of the hider.
I constrained the height of the hider to equal the height of the green view plus 12. The 12 will make the white margin between the green view and the line. I set this constraint's priority to 999. This means auto layout will try very hard to satisfy the constraint, but will break this constraint if necessary in order to satisfy all required constraints.
I created a constraint setting the hider's height to zero. I connected this constraint to an outlet named hiderHeightConstraint in my view controller. Note that this means there are two constraints on the hider's height. This one forces the hider's height to zero and is required. The other (created in the prior step) sets the hider's height to the green view's height plus padding, but is not required. When you are editing the layout in the storyboard, you probably want to turn off this constraint by turning off its “Installed” check box in the constraint's Attributes inspector.
I connected the “Toggle Secret Message” button to this action:
#IBAction private func toggleButtonWasTapped() {
UIView.animate(withDuration: 0.7) {
self.hiderHeightConstraint.isActive.toggle()
self.view.layoutIfNeeded()
}
}
Here's how it works. When the hiderHeightConstraint is active, the hider is forced to zero height. Since it clips its subviews, the green view is not visible. Since the constraint between the hider's height and the green view's height is not required, the green view can still be its natural size. The other constraints (leading/trailing/top) force the green view to stick out beyond the bottom edge of the hider.
When the hiderHeightConstraint is not active, the hider grows to the height of the green view plus the padding, allowing the green view to be fully visible.
Here is what my storyboard looks like:
This is one approach you can follow to achieve this:
Take 2 Container UIView and 2 line view (you may take UIView again) and 2 UIImageView (or any for green view). So your StoryBoard should look like this :
Make sure your container views are clips to bound (you can set it from storyboard only).
Now you can achieve the animation easily by CGAffineTransform.
I will call outlet names for animated view as imageViewOne and imageViewTwo.
In viewDidLoad() write this (if initially views are hidden):
imageViewOne.transform = CGAffineTransform(translationX: 0.0, y: containerViewOne.bounds.height)
imageViewTwo.transform = CGAffineTransform(translationX: 0.0, y: -containerViewOne.bounds.height)
Then to show it with animation:
//To build out of line
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
self.imageViewOne.transform = .identity
self.imageViewTwo.transform = .identity
}, completion: nil)
//To build into line
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
self.imageViewOne.transform = CGAffineTransform(translationX: 0.0, y: containerViewOne.bounds.height)
self.imageViewTwo.transform = CGAffineTransform(translationX: 0.0, y: -containerViewOne.bounds.height)
}, completion: nil)
Use a view but then put in that view the line to make it look authentic.
Then when you are done make the whole animation disappear or if you want to make other animations go over it , you can call functions to move views above others
https://stackoverflow.com/a/38780829/4674760

Swift: Round UIButton with Blur background

I am wanting to make a round UIButton but with a light blur effect with vibrancy as it's background
So far I've got a rounded UIButton, but the code I have found online (I'm new to iOS development so don't really understand how the blur etc works) to add a blur just puts it as the entire button's frame, essentially making the button appear square again.
I've also tried adding a view, then the UIButton and then the blur effect and applied the cornerRadius code to that view but it also didn't work.
Here is what I've tried:
shortcutButton.layer.cornerRadius = 0.5 * shortcutButton.bounds.size.width // add the round corners in proportion to the button size
let blur = UIVisualEffectView(effect: UIBlurEffect(style:
UIBlurEffectStyle.Light))
blur.frame = shortcutButton.bounds
blur.userInteractionEnabled = false //This allows touches to forward to the button.
shortcutButton.insertSubview(blur, atIndex: 0)
Add the following two lines of code to your project, before you add the subview:
blur.layer.cornerRadius = 0.5 * shortcutButton.bounds.size.width
blur.clipsToBounds = true
Enjoy! :)