Tableview Xib Shadow Swift












1















Here is what I am trying to do:



Original Screen Shot



The screenshot is taken from Iphone:



Taken Screenshot



This is my code:



cell.shadowLayerView.layer.masksToBounds = false
cell.shadowLayerView.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.shadowLayerView.layer.shadowColor = UIColor.black.cgColor
cell.shadowLayerView.layer.shadowOpacity = 0.23
cell.shadowLayerView.layer.shadowRadius = 4
cell.shadowLayerView.layer.shadowPath = UIBezierPath(roundedRect: cell.shadowLayerView.bounds, cornerRadius: 2).cgPath
cell.shadowLayerView.layer.shouldRasterize = true
cell.shadowLayerView.layer.rasterizationScale = UIScreen.main.scale
cell.discriptionLbl.frame.size.width = UIScreen.main.bounds.size.width


This is my tableview xib. In original image show light gray color shadow all side(Top,Bottom,left,Right) but in taken image show all side shadow but why show extra shadow in right side and bottom side.



See Below Image:



Latest Taken Image



Question: How to show same shadow from all side of the view like original image(shadow in light gray color)?



Can someone please explain to me how to solve this , i've tried to solve this issue but no results yet.



Any help would be greatly appreciated.



Thanks in advance.










share|improve this question

























  • this link may help you to get what you want

    – Muhammad Umair Gillani
    Jan 1 at 13:11






  • 2





    Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

    – Magnas
    Jan 1 at 13:12











  • set the shadow for cell contentView

    – a.masri
    Jan 1 at 13:33











  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30
















1















Here is what I am trying to do:



Original Screen Shot



The screenshot is taken from Iphone:



Taken Screenshot



This is my code:



cell.shadowLayerView.layer.masksToBounds = false
cell.shadowLayerView.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.shadowLayerView.layer.shadowColor = UIColor.black.cgColor
cell.shadowLayerView.layer.shadowOpacity = 0.23
cell.shadowLayerView.layer.shadowRadius = 4
cell.shadowLayerView.layer.shadowPath = UIBezierPath(roundedRect: cell.shadowLayerView.bounds, cornerRadius: 2).cgPath
cell.shadowLayerView.layer.shouldRasterize = true
cell.shadowLayerView.layer.rasterizationScale = UIScreen.main.scale
cell.discriptionLbl.frame.size.width = UIScreen.main.bounds.size.width


This is my tableview xib. In original image show light gray color shadow all side(Top,Bottom,left,Right) but in taken image show all side shadow but why show extra shadow in right side and bottom side.



See Below Image:



Latest Taken Image



Question: How to show same shadow from all side of the view like original image(shadow in light gray color)?



Can someone please explain to me how to solve this , i've tried to solve this issue but no results yet.



Any help would be greatly appreciated.



Thanks in advance.










share|improve this question

























  • this link may help you to get what you want

    – Muhammad Umair Gillani
    Jan 1 at 13:11






  • 2





    Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

    – Magnas
    Jan 1 at 13:12











  • set the shadow for cell contentView

    – a.masri
    Jan 1 at 13:33











  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30














1












1








1








Here is what I am trying to do:



Original Screen Shot



The screenshot is taken from Iphone:



Taken Screenshot



This is my code:



cell.shadowLayerView.layer.masksToBounds = false
cell.shadowLayerView.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.shadowLayerView.layer.shadowColor = UIColor.black.cgColor
cell.shadowLayerView.layer.shadowOpacity = 0.23
cell.shadowLayerView.layer.shadowRadius = 4
cell.shadowLayerView.layer.shadowPath = UIBezierPath(roundedRect: cell.shadowLayerView.bounds, cornerRadius: 2).cgPath
cell.shadowLayerView.layer.shouldRasterize = true
cell.shadowLayerView.layer.rasterizationScale = UIScreen.main.scale
cell.discriptionLbl.frame.size.width = UIScreen.main.bounds.size.width


This is my tableview xib. In original image show light gray color shadow all side(Top,Bottom,left,Right) but in taken image show all side shadow but why show extra shadow in right side and bottom side.



See Below Image:



Latest Taken Image



Question: How to show same shadow from all side of the view like original image(shadow in light gray color)?



Can someone please explain to me how to solve this , i've tried to solve this issue but no results yet.



Any help would be greatly appreciated.



Thanks in advance.










share|improve this question
















Here is what I am trying to do:



Original Screen Shot



The screenshot is taken from Iphone:



Taken Screenshot



This is my code:



cell.shadowLayerView.layer.masksToBounds = false
cell.shadowLayerView.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.shadowLayerView.layer.shadowColor = UIColor.black.cgColor
cell.shadowLayerView.layer.shadowOpacity = 0.23
cell.shadowLayerView.layer.shadowRadius = 4
cell.shadowLayerView.layer.shadowPath = UIBezierPath(roundedRect: cell.shadowLayerView.bounds, cornerRadius: 2).cgPath
cell.shadowLayerView.layer.shouldRasterize = true
cell.shadowLayerView.layer.rasterizationScale = UIScreen.main.scale
cell.discriptionLbl.frame.size.width = UIScreen.main.bounds.size.width


This is my tableview xib. In original image show light gray color shadow all side(Top,Bottom,left,Right) but in taken image show all side shadow but why show extra shadow in right side and bottom side.



See Below Image:



Latest Taken Image



Question: How to show same shadow from all side of the view like original image(shadow in light gray color)?



Can someone please explain to me how to solve this , i've tried to solve this issue but no results yet.



Any help would be greatly appreciated.



Thanks in advance.







ios css swift uitableview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 6:30







Sam

















asked Jan 1 at 12:59









SamSam

655218




655218













  • this link may help you to get what you want

    – Muhammad Umair Gillani
    Jan 1 at 13:11






  • 2





    Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

    – Magnas
    Jan 1 at 13:12











  • set the shadow for cell contentView

    – a.masri
    Jan 1 at 13:33











  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30



















  • this link may help you to get what you want

    – Muhammad Umair Gillani
    Jan 1 at 13:11






  • 2





    Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

    – Magnas
    Jan 1 at 13:12











  • set the shadow for cell contentView

    – a.masri
    Jan 1 at 13:33











  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30

















this link may help you to get what you want

– Muhammad Umair Gillani
Jan 1 at 13:11





this link may help you to get what you want

– Muhammad Umair Gillani
Jan 1 at 13:11




2




2





Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

– Magnas
Jan 1 at 13:12





Supplying only a link as an answer is discouraged. The link can break if the page moves. Please consider explaining the basics of the answer you are providing since we’re not here to do basic searches that the OP could do themselves.

– Magnas
Jan 1 at 13:12













set the shadow for cell contentView

– a.masri
Jan 1 at 13:33





set the shadow for cell contentView

– a.masri
Jan 1 at 13:33













update question please check and give me solution.

– Sam
Jan 2 at 6:30





update question please check and give me solution.

– Sam
Jan 2 at 6:30












2 Answers
2






active

oldest

votes


















1














See the below code:



mainViewCorner.layer.shadowColor = UIColor.red.cgColor;
mainViewCorner.layer.shadowOffset = CGSize.zero //direction of shadow
mainViewCorner.layer.shadowOpacity = 1.0; // opacity for shadow
mainViewCorner.layer.shadowRadius = 0.0; //amount of shadow to blur
mainViewCorner.layer.cornerRadius = 4.0;


issue with your code was shadowOffset. It defines the direction of your shadow. If you want shadow on all sides - it must have zero value for both width and height.






share|improve this answer


























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











  • @Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

    – Mehul Thakkar
    Jan 2 at 6:33











  • In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

    – Mehul Thakkar
    Jan 2 at 6:35











  • Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

    – Sam
    Jan 2 at 6:38











  • You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

    – Mehul Thakkar
    Jan 2 at 6:38



















0














try it



   myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.masksToBounds = false
myView.layer.shadowColor = UIColor.gray.cgColor
myView.layer.shadowOffset = CGSize(width: 0, height: 2)
myView.layer.shadowOpacity = 0.5


Or you can use Sketch Shadow



extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}


apply Sketch Shadow



 myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.applySketchShadow(
color: .black,
alpha: 0.5,
x: CGFloat(0),
y: CGFloat(10),
blur: 20,
spread: 0)
myView.layer.shadowPath = shadowPath.cgPath





share|improve this answer
























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995639%2ftableview-xib-shadow-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














See the below code:



mainViewCorner.layer.shadowColor = UIColor.red.cgColor;
mainViewCorner.layer.shadowOffset = CGSize.zero //direction of shadow
mainViewCorner.layer.shadowOpacity = 1.0; // opacity for shadow
mainViewCorner.layer.shadowRadius = 0.0; //amount of shadow to blur
mainViewCorner.layer.cornerRadius = 4.0;


issue with your code was shadowOffset. It defines the direction of your shadow. If you want shadow on all sides - it must have zero value for both width and height.






share|improve this answer


























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











  • @Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

    – Mehul Thakkar
    Jan 2 at 6:33











  • In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

    – Mehul Thakkar
    Jan 2 at 6:35











  • Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

    – Sam
    Jan 2 at 6:38











  • You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

    – Mehul Thakkar
    Jan 2 at 6:38
















1














See the below code:



mainViewCorner.layer.shadowColor = UIColor.red.cgColor;
mainViewCorner.layer.shadowOffset = CGSize.zero //direction of shadow
mainViewCorner.layer.shadowOpacity = 1.0; // opacity for shadow
mainViewCorner.layer.shadowRadius = 0.0; //amount of shadow to blur
mainViewCorner.layer.cornerRadius = 4.0;


issue with your code was shadowOffset. It defines the direction of your shadow. If you want shadow on all sides - it must have zero value for both width and height.






share|improve this answer


























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











  • @Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

    – Mehul Thakkar
    Jan 2 at 6:33











  • In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

    – Mehul Thakkar
    Jan 2 at 6:35











  • Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

    – Sam
    Jan 2 at 6:38











  • You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

    – Mehul Thakkar
    Jan 2 at 6:38














1












1








1







See the below code:



mainViewCorner.layer.shadowColor = UIColor.red.cgColor;
mainViewCorner.layer.shadowOffset = CGSize.zero //direction of shadow
mainViewCorner.layer.shadowOpacity = 1.0; // opacity for shadow
mainViewCorner.layer.shadowRadius = 0.0; //amount of shadow to blur
mainViewCorner.layer.cornerRadius = 4.0;


issue with your code was shadowOffset. It defines the direction of your shadow. If you want shadow on all sides - it must have zero value for both width and height.






share|improve this answer















See the below code:



mainViewCorner.layer.shadowColor = UIColor.red.cgColor;
mainViewCorner.layer.shadowOffset = CGSize.zero //direction of shadow
mainViewCorner.layer.shadowOpacity = 1.0; // opacity for shadow
mainViewCorner.layer.shadowRadius = 0.0; //amount of shadow to blur
mainViewCorner.layer.cornerRadius = 4.0;


issue with your code was shadowOffset. It defines the direction of your shadow. If you want shadow on all sides - it must have zero value for both width and height.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 6:42

























answered Jan 1 at 13:33









Mehul ThakkarMehul Thakkar

9,73273764




9,73273764













  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











  • @Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

    – Mehul Thakkar
    Jan 2 at 6:33











  • In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

    – Mehul Thakkar
    Jan 2 at 6:35











  • Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

    – Sam
    Jan 2 at 6:38











  • You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

    – Mehul Thakkar
    Jan 2 at 6:38



















  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30











  • @Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

    – Mehul Thakkar
    Jan 2 at 6:33











  • In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

    – Mehul Thakkar
    Jan 2 at 6:35











  • Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

    – Sam
    Jan 2 at 6:38











  • You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

    – Mehul Thakkar
    Jan 2 at 6:38

















update question please check and give me solution.

– Sam
Jan 2 at 6:30





update question please check and give me solution.

– Sam
Jan 2 at 6:30













@Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

– Mehul Thakkar
Jan 2 at 6:33





@Sam : Have you read my answer, I already explained that, shadowOffset defines the direction for your shadow. So, if you want shadow equal in all directions, then shadowOffset must be CGSize.zero

– Mehul Thakkar
Jan 2 at 6:33













In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

– Mehul Thakkar
Jan 2 at 6:35





In what you have tried - please remove shadowPath, As you are using shadowPath and shadowOffset both, it will get conflict

– Mehul Thakkar
Jan 2 at 6:35













Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

– Sam
Jan 2 at 6:38





Ya @Mehul you are right you solve my problem thank you very much please explain when i m trying to CGSize(width: 0.0, height: 0.0) and cgsize.zero is not same ?//

– Sam
Jan 2 at 6:38













You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

– Mehul Thakkar
Jan 2 at 6:38





You can see answer of Dipen in this question(Dont forget to read comments in the code he provided, otherwise it will not work): stackoverflow.com/questions/36173052/…,

– Mehul Thakkar
Jan 2 at 6:38













0














try it



   myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.masksToBounds = false
myView.layer.shadowColor = UIColor.gray.cgColor
myView.layer.shadowOffset = CGSize(width: 0, height: 2)
myView.layer.shadowOpacity = 0.5


Or you can use Sketch Shadow



extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}


apply Sketch Shadow



 myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.applySketchShadow(
color: .black,
alpha: 0.5,
x: CGFloat(0),
y: CGFloat(10),
blur: 20,
spread: 0)
myView.layer.shadowPath = shadowPath.cgPath





share|improve this answer
























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30
















0














try it



   myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.masksToBounds = false
myView.layer.shadowColor = UIColor.gray.cgColor
myView.layer.shadowOffset = CGSize(width: 0, height: 2)
myView.layer.shadowOpacity = 0.5


Or you can use Sketch Shadow



extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}


apply Sketch Shadow



 myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.applySketchShadow(
color: .black,
alpha: 0.5,
x: CGFloat(0),
y: CGFloat(10),
blur: 20,
spread: 0)
myView.layer.shadowPath = shadowPath.cgPath





share|improve this answer
























  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30














0












0








0







try it



   myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.masksToBounds = false
myView.layer.shadowColor = UIColor.gray.cgColor
myView.layer.shadowOffset = CGSize(width: 0, height: 2)
myView.layer.shadowOpacity = 0.5


Or you can use Sketch Shadow



extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}


apply Sketch Shadow



 myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.applySketchShadow(
color: .black,
alpha: 0.5,
x: CGFloat(0),
y: CGFloat(10),
blur: 20,
spread: 0)
myView.layer.shadowPath = shadowPath.cgPath





share|improve this answer













try it



   myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.masksToBounds = false
myView.layer.shadowColor = UIColor.gray.cgColor
myView.layer.shadowOffset = CGSize(width: 0, height: 2)
myView.layer.shadowOpacity = 0.5


Or you can use Sketch Shadow



extension CALayer {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0)
{
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2.0
if spread == 0 {
shadowPath = nil
} else {
let dx = -spread
let rect = bounds.insetBy(dx: dx, dy: dx)
shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}


apply Sketch Shadow



 myView.layer.cornerRadius = 10
let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: 10)

myView.layer.applySketchShadow(
color: .black,
alpha: 0.5,
x: CGFloat(0),
y: CGFloat(10),
blur: 20,
spread: 0)
myView.layer.shadowPath = shadowPath.cgPath






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 13:40









a.masria.masri

1,7531721




1,7531721













  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30



















  • update question please check and give me solution.

    – Sam
    Jan 2 at 6:30

















update question please check and give me solution.

– Sam
Jan 2 at 6:30





update question please check and give me solution.

– Sam
Jan 2 at 6:30


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995639%2ftableview-xib-shadow-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith