Make the UIImage to the rounded form? [closed] - swift

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I tried the bellow code then I got the result like above image
Expected result for Image view is shown bellow
I have posted the image of expectated result.
I have dragged the UIImage view and I want to make the image view that display in round format.
So please guide me out.
#IBOutlet weak var imgView : UIImageView!
imgView.layer.borderWidth = 1
imgView.layer.masksToBounds = true
imgView.layer.borderColor = UIColor.black.cgColor
imgView.layer.cornerRadius = imgView.frame.width/2
imgView.clipsToBounds = true
//I tried this still not getting the answer

UIImageView is subclass of UIView. Each UIView has its own CALayer. You can set the border color, border width and corner radius of the view by using its layer. To show the UIImageView in circular shape, first height and weight of the view should be equal and then set corner radius as height/2 or width/2.
If myImage is UIImageView for which height and weight are equal, then:
myImage.layer.cornerRadius = myImage.frame.size.height / 2

Simply you can do that like following
override func viewDidLoad() {
super.viewDidLoad()
profilePhoto.layer.borderWidth = 1
profilePhoto.layer.borderColor = UIColor.black.cgColor
profilePhoto.layer.masksToBounds = false
profilePhoto.layer.cornerRadius = profilePhoto.frame.width/2
profilePhoto.clipsToBounds = true
}

Step1: You can do this by using custom view class. Create a new swift file and set name to UIImageViewX then paste the below code.
import UIKit
#IBDesignable
class UIImageViewX: UIImageView {
// MARK: - Properties
#IBInspectable public var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}
#IBInspectable public var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
#IBInspectable public var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
#IBInspectable var pulseDelay: Double = 0.0
#IBInspectable var popIn: Bool = false
#IBInspectable var popInDelay: Double = 0.4
// MARK: - Shadow
#IBInspectable public var shadowOpacity: CGFloat = 0 {
didSet {
//layer.shadowOpacity = Float(shadowOpacity)
}
}
#IBInspectable public var shadowColor: UIColor = UIColor.clear {
didSet {
//layer.shadowColor = shadowColor.cgColor
}
}
#IBInspectable public var shadowRadius: CGFloat = 0 {
didSet {
//layer.shadowRadius = shadowRadius
}
}
#IBInspectable public var shadowOffsetY: CGFloat = 0 {
didSet {
//layer.shadowOffset.height = shadowOffsetY
}
}
// MARK: - FUNCTIONS
override func layoutSubviews() {
// super.layoutSubviews()
// layer.shadowColor = shadowColor.cgColor
// layer.shadowOpacity = Float(shadowOpacity)
// layer.shadowRadius = shadowRadius
// layer.masksToBounds = false
// layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
}
override func draw(_ rect: CGRect) {
if clipsToBounds && shadowOpacity > 0 {
layer.masksToBounds = true
layer.cornerRadius = cornerRadius
// Outer UIView to hold the Shadow
let shadow = UIView(frame: rect)
shadow.layer.cornerRadius = cornerRadius
shadow.layer.masksToBounds = false
shadow.layer.shadowOpacity = Float(shadowOpacity)
shadow.layer.shadowColor = shadowColor.cgColor
shadow.layer.shadowRadius = shadowRadius
shadow.layer.shadowOffset.height = shadowOffsetY
shadow.layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
shadow.addSubview(self)
}
}
override func awakeFromNib() {
if pulseDelay > 0 {
UIView.animate(withDuration: 1, delay: pulseDelay, usingSpringWithDamping: 0.4, initialSpringVelocity: 0, options: [], animations: {
self.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
self.transform = CGAffineTransform.identity
}, completion: nil)
}
if popIn {
transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
UIView.animate(withDuration: 0.8, delay: popInDelay, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: .allowUserInteraction, animations: {
self.transform = CGAffineTransform.identity
}, completion: nil)
}
}
}
Step2:
Set custom class in storyboard like above image.
Step3:
After this you can see the corner radius properties of imageview in Attribute section.
Increase and decrease the corner radius then you will got the desire result

You can round an imageView using the CALayer, use this class to do it in the storyboard:
#IBDesignable class RoundImageView: UIImageView
{
#IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
#IBInspectable var borderColor: UIColor? = nil
{
didSet {
layer.borderColor = borderColor?.cgColor
}
}
#IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
#IBInspectable var dropShadowOffset: CGSize = CGSize(width: 0, height: 0) {
didSet {
layer.shadowOffset = dropShadowOffset
}
}
#IBInspectable var maskToBounds: Bool = true {
didSet{
layer.masksToBounds = maskToBounds
}
}
#IBInspectable var dropShadowColor: UIColor? {
didSet {
layer.shadowColor = dropShadowColor?.cgColor
}
}
#IBInspectable var dropShadowRadius: CGFloat = 0 {
didSet {
layer.shadowRadius = dropShadowRadius
}
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
}
override init(frame: CGRect)
{
super.init(frame: frame)
}
}

Related

The problem with gradiant layer in the UIBUTTON in swift

now I am designing button with gradient layer like show in the picture
I have two problems
1- when I add gradient layer to the button the text disappear like show in the last figure
2- The gradient layer I have created does not like the design the left side of the color in the real design alpha less than right ,I have added the right code but does not show what I want
-This parameters what I am using
#IBDesignable
class buttonGeneralDesign: UIButton {
private var gradientLayer: CAGradientLayer!
#IBInspectable
var cornerRadius: CGFloat = 0.0{
didSet{
self.layer.cornerRadius = cornerRadius
self.clipsToBounds = false
}
}
#IBInspectable
var borderColor: UIColor = .clear {
didSet {
self.layer.borderColor = borderColor.cgColor
}
}
#IBInspectable
var borderWidth: CGFloat = 0.0 {
didSet {
self.layer.borderWidth = borderWidth
}
}
#IBInspectable
var shadowColor: UIColor = .clear {
didSet {
self.layer.shadowColor = shadowColor.cgColor
}
}
#IBInspectable
var shadowRadius: CGFloat = 0.0 {
didSet{
self.layer.shadowRadius = shadowRadius
}
}
#IBInspectable
var shadowOpacity: Float = 0.0 {
didSet{
self.layer.shadowOpacity = shadowOpacity
}
}
#IBInspectable
var shadowOffset: CGSize = CGSize.zero{
didSet{
self.layer.shadowOffset = shadowOffset
}
}
#IBInspectable var topColor: UIColor = .red {
didSet {
setNeedsLayout()
}
}
#IBInspectable var bottomColor: UIColor = .yellow {
didSet {
setNeedsLayout()
}
}
#IBInspectable var startPointX: CGFloat = 0 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var startPointY: CGFloat = 0.5 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var endPointX: CGFloat = 1 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var endPointY: CGFloat = 0.5 {
didSet {
setNeedsLayout()
}
}
// override class var layerClass: AnyClass {
// return CAGradientLayer.self
// }
override func layoutSubviews() {
self.gradientLayer = CAGradientLayer()
self.gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor]
self.gradientLayer.startPoint = CGPoint(x: startPointX, y: startPointY)
self.gradientLayer.locations = [0,1]
self.gradientLayer.endPoint = CGPoint(x: endPointX, y: endPointY)
self.gradientLayer.position = self.center
self.layer.insertSublayer( self.gradientLayer, at: 0)
}
}
-This is the real design
This is output of the app
First: don't insert layer in layoutSubview because it calls many
times
Second: Use below or above when inserting layer
Third: use self.gradientLayer.frame = self.bounds instead of self.gradientLayer.position = self.center
.
import UIKit
#IBDesignable
class buttonGeneralDesign: UIButton {
private var gradientLayer: CAGradientLayer!
#IBInspectable
var cornerRadius: CGFloat = 0.0{
didSet{
self.layer.cornerRadius = cornerRadius
self.clipsToBounds = false
}
}
#IBInspectable
var borderColor: UIColor = .clear {
didSet {
self.layer.borderColor = borderColor.cgColor
}
}
#IBInspectable
var borderWidth: CGFloat = 0.0 {
didSet {
self.layer.borderWidth = borderWidth
}
}
#IBInspectable
var shadowColor: UIColor = .clear {
didSet {
self.layer.shadowColor = shadowColor.cgColor
}
}
#IBInspectable
var shadowRadius: CGFloat = 0.0 {
didSet{
self.layer.shadowRadius = shadowRadius
}
}
#IBInspectable
var shadowOpacity: Float = 0.0 {
didSet{
self.layer.shadowOpacity = shadowOpacity
}
}
#IBInspectable
var shadowOffset: CGSize = CGSize.zero{
didSet{
self.layer.shadowOffset = shadowOffset
}
}
#IBInspectable var topColor: UIColor = .red {
didSet {
setNeedsLayout()
}
}
#IBInspectable var bottomColor: UIColor = .yellow {
didSet {
setNeedsLayout()
}
}
#IBInspectable var startPointX: CGFloat = 0 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var startPointY: CGFloat = 0.5 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var endPointX: CGFloat = 1 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var endPointY: CGFloat = 0.5 {
didSet {
setNeedsLayout()
}
}
override init(frame: CGRect) {
super.init(frame: .zero)
commonInit()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}
func commonInit(){
self.gradientLayer = CAGradientLayer()
self.gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor]
self.gradientLayer.startPoint = CGPoint(x: startPointX, y: startPointY)
self.gradientLayer.locations = [0,1]
self.gradientLayer.endPoint = CGPoint(x: endPointX, y: endPointY)
self.layer.insertSublayer( self.gradientLayer, below: self.titleLabel?.layer)
}
override func layoutSubviews() {
self.gradientLayer.frame = self.bounds
}
}
func SetupGradientLeft2Right() {
let gradient:CAGradientLayer = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [UIColor.green.cgColor,UIColor.yellow.cgColor]
gradient.startPoint = CGPoint(x: 0.0, y: 1.0)
gradient.endPoint = CGPoint(x: 1.0, y: 1.0)
self.layer.insertSublayer(gradient, at: 0)
}

Weird behavior with UIView / Shadow while transition the constraint (Pictures inside)

I have something like a SlideUp View with a TableView inside. I am changing the constraint of my SlideUp View to increase the width. However, this is the result on sliding it up or down:
The result on slide down:
The result on slide up:
When the transition is finished, everything is normal:
This is the Code for my shadowed ViewContainer inside the TableView:
import UIKit
#IBDesignable class ShadowedView: UIView {
#IBInspectable var shadowed: Bool = true {
didSet {
setNeedsLayout()
}
}
#IBInspectable var cornerRadius: CGFloat = 0.0 {
didSet {
setNeedsLayout()
}
}
#IBInspectable var shadowRadius: CGFloat = 0.0 {
didSet {
setNeedsLayout()
}
}
override func layoutSubviews () {
super.layoutSubviews()
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 1
layer.shadowRadius = shadowRadius
layer.shadowOffset = CGSize(width: 0, height: 0)
layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: cornerRadius).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.main.scale
}
}
Where is this behavior coming from and how can I prevent it?

How to set corner radius to a collection of UIButtons

I'm new at using Xcode. My question is regarding "How to set corner.Radius for UIButtons (collection) instead of doing 1 by 1. Once the collection is created i'm using the following line:
self.myButtons.layer.cornerRadius = 10
but that is for a single button. Is it possible to do this for a "collection" of buttons?
enter image description here
any help is greatly appreciated.
#IBOutlet var myButtons: [UIButton]!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.myButtons.layer.conerRadius = 10
A few options:
Iterate through them yourself:
myButtons.forEach { $0.layer.cornerRadius = 10 }
Use NSArray and its setValue(_:forKey:)
(myButtons as NSArray).setValue(10, forKey: "cornerRadius")
I’d lean towards the former, but the latter is the old Objective-C way of doing it (which is why we had to bridge to NSArray).
The other approach is to define your own UIButton subclass, e.g. RoundedButton that does this for you. Just set the base class for your button in IB to be your custom subclass.
E.g. for fixed corner radius (which you can also adjust right in IB):
#IBDesignable
class RoundedButton: UIButton {
#IBInspectable var cornerRadius: CGFloat = 10 {
didSet {
layer.cornerRadius = cornerRadius
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
override init(frame: CGRect = .zero) {
super.init(frame: frame)
configure()
}
}
private extension RoundedButton {
func configure() {
layer.cornerRadius = cornerRadius
}
}
Or, if you want dynamic rounding based upon the height:
#IBDesignable
class RoundedButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
let radius = min(bounds.width, bounds.height) / 2
layer.cornerRadius = radius
}
}
The virtue of this approach is that you can see your rounded buttons rendered right in IB.
Follow this below steps -
1.Choose UIButton from the object library
2.Drag to your storyboard
3.Choose border style as none.
4.Create a Swift file and add this below extension -
extension UIView {
#IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
#IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
#IBInspectable var borderColor: UIColor? {
get {
return UIColor(cgColor: layer.borderColor!)
}
set {
layer.borderColor = newValue?.cgColor
}
}
}
extension UIButton {
func roundedButton(){
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
}
}
extension UITextField {
func setLeftPaddingPoints(_ amount:CGFloat){
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
}
func setRightPaddingPoints(_ amount:CGFloat) {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
}
}
extension UITextField {
#IBInspectable var maxLength: Int {
get {
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int {
return length
} else {
return Int.max
}
}
set {
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
}
}
#objc func checkMaxLength(textField: UITextField) {
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else {
return
}
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
}
}
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UIView,UIButton,UITexfield.Try this Method.
Hope this method also helps.
/// Other way to set Corner radius of view; also inspectable from Storyboard.
public extension UIView {
#IBInspectable public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
// layer.masksToBounds = true
layer.cornerRadius = abs(CGFloat(Int(newValue * 100)) / 100)
}
}}
By usisng this you can set border radius from storyboard
OR
for btn in yourbuttonCollectionName {btn.cornerRadius = 10.0}
You can do this in interface builder. Select your button and then tap the "Identity Inspector" (3rd tab on the right). Under "User Defined Runtime Attributes" hit the plus button. and type layer.conerRadius for the key and 1 for the value. This will set the corner radius by KVO. you can now copy this button or duplicate it with alt+drag and the copies will also have the corner radius (note it doesn't show in the preview window, but it will show at run time).
Alternatively in code:
myButtons.forEach { button in
button.layer.cornerRadius = 1
}
If you are using an outlet collection you can do this in a didSet since that will be called when iOS sets the outlet from the nib file/ storyboard.
extension UIView {
func addCornerRadius(_ radius: CGFloat) {
self.layer.cornerRadius = radius
}
func applyBorder(_ width: CGFloat, borderColor: UIColor) {
self.layer.borderWidth = width
self.layer.borderColor = borderColor.cgColor
}
func addShadow(color: UIColor, opacity: Float, offset: CGSize, radius: CGFloat) {
self.layer.shadowColor = color.cgColor
self.layer.shadowOpacity = opacity
self.layer.shadowOffset = offset
self.layer.shadowRadius = radius
}
func displayToast(message: String) {
let style = CSToastStyle(defaultStyle: ())
style?.backgroundColor = UIColor.black
style?.titleColor = UIColor.white
style?.messageColor = UIColor.white
makeToast(message, duration: 3.0, position: CSToastPositionTop, style: style)
} }
Use As Below :
self.view.addCornerRadius(10)
self.view.addShadow(color: .lightGray, opacity: 1.0, offset: CGSize(width: 1, height: 1), radius: 2)

CornerRadius and Shadow on a UIView using #IBInspectable Swift 4.2

Is it possible to have both CornerRaduis and a shadow on a UIView?
I set up a Custom class for a UIView which uses #IBInspectable to set a cornerRadius and a addShadow which can be true or false. When I set the cornerRadius the shadow doesn't display, if I take away the cornerRadius then it displays again. Thanks in advance!
Custom class:
import UIKit
class CustomUIView: UIView {
override func awakeFromNib() {
self.layer.masksToBounds = cornerRadius > 0
}
#IBInspectable var useDefaultRadius: Bool = true {
didSet {
self.layer.masksToBounds = cornerRadius > 0
}
}
#IBInspectable var cornerRadius: CGFloat {
set {
self.layer.cornerRadius = newValue
}
get {
if (useDefaultRadius) {
// Set default radius
self.layer.cornerRadius = 23
}
return self.layer.cornerRadius
}
}
#IBInspectable var addShadow:Bool = true{
didSet(newValue) {
if(newValue == true){
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.5
self.layer.shadowOffset = CGSize(width: 2, height: 3)
self.layer.shadowRadius = 3
self.layer.shadowPath = UIBezierPath(rect: bounds).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
print("trying to use shadow")
}
}
}
}
Rather than creating custom clas and changing class of uiview everytime, i prefer extending it.
I'm achieving this by extending UIView as mentioned below:
extension UIView {
#IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
#IBInspectable
var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
#IBInspectable
var borderColor: UIColor? {
get {
let color = UIColor.init(cgColor: layer.borderColor!)
return color
}
set {
layer.borderColor = newValue?.cgColor
}
}
#IBInspectable
var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowRadius = shadowRadius
}
}
#IBInspectable
var shadowOffset : CGSize{
get{
return layer.shadowOffset
}set{
layer.shadowOffset = newValue
}
}
#IBInspectable
var shadowColor : UIColor{
get{
return UIColor.init(cgColor: layer.shadowColor!)
}
set {
layer.shadowColor = newValue.cgColor
}
}
#IBInspectable
var shadowOpacity : Float {
get{
return layer.shadowOpacity
}
set {
layer.shadowOpacity = newValue
}
}
}
And set properties in storyboard as:
That's it.
Hope this helps.
Set true masksToBounds in addShadow:Bool or you don't need to set masksToBounds in addShadow:Bool didSet method
#IBInspectable var addShadow:Bool = true{
didSet(newValue) {
if(newValue == true){
//self.layer.masksToBounds = false
self.layer.masksToBounds = true
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.5
self.layer.shadowOffset = CGSize(width: 2, height: 3)
self.layer.shadowRadius = 3
self.layer.shadowPath = UIBezierPath(rect: bounds).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
print("trying to use shadow")
}
}
}
You can follow: https://medium.com/bytes-of-bits/swift-tips-adding-rounded-corners-and-shadows-to-a-uiview-691f67b83e4a
https://spin.atomicobject.com/2017/07/18/swift-interface-builder/
Here's the trick, you have to Set true to masksToBounds then Set false to masksToBounds before adding shadow code.
you can check this method to make things clear:
func addShadow(color: UIColor, bottomOrTop: Bool = false, radius: CGFloat = 2, height: CGFloat = 3) {
// These below line makes the trick to draw shadow with corner radius
self.layer.masksToBounds = true
self.layer.masksToBounds = false
self.layer.shadowOffset = CGSize(width: height, height: bottomOrTop ? height : height * -1)
self.layer.shadowRadius = radius
self.layer.shadowColor = color.cgColor
self.layer.shadowOpacity = 0.3
}

Swift 3 xcode storyboard, add box-shadow to UIView, like a CSS style box-shadow

As you can see, I would like to add a shadow around the edges of each UIView in the cells as white on gray hard to see it's borders clearly.
Set your view's shadow properties to add a shadow.
SWIFT 3
YourView.layer.shadowOpacity = 0.7
YourView.layer.shadowOffset = CGSize(width: 3, height: 3)
YourView.layer.shadowRadius = 15.0
YourView.layer.shadowColor = UIColor.darkGray.cgColor
NOTE: replace YourView with the view you want shadow.
here is my approach to this:
You create a new class called ShadowView.
import UIKit
#IBDesignable
class ShadowView: UIView {
//Shadow
#IBInspectable var shadowColor: UIColor = UIColor.black {
didSet {
self.updateView()
}
}
#IBInspectable var shadowOpacity: Float = 0.5 {
didSet {
self.updateView()
}
}
#IBInspectable var shadowOffset: CGSize = CGSize(width: 3, height: 3) {
didSet {
self.updateView()
}
}
#IBInspectable var shadowRadius: CGFloat = 15.0 {
didSet {
self.updateView()
}
}
//Apply params
func updateView() {
self.layer.shadowColor = self.shadowColor.cgColor
self.layer.shadowOpacity = self.shadowOpacity
self.layer.shadowOffset = self.shadowOffset
self.layer.shadowRadius = self.shadowRadius
}
}
Then you can apply this class for you view in the storyboard like:
Now you can edit the values in the attributes inspector:
You can select opacity as you want.
override func awakeFromNib()
{
super.awakeFromNib()
self.viewContainer.layer.shadowOffset = CGSize(width: 0, height: 1) // CGSizeMake(0, 1)
self.viewContainer.layer.shadowColor = UIColor.black.cgColor
self.viewContainer.layer.shadowRadius = 1.5
self.viewContainer.layer.shadowOpacity = 0.65
self.viewContainer.layer.cornerRadius = 1
self.viewContainer.clipsToBounds = true
self.viewContainer.layer.masksToBounds = false
self.layer.masksToBounds = false
}