Opacity Or Alpha issue - Different Look in screen and while export in Photos in swift

30 views Asked by At

Hierarchy Of View ===> CTStickerView(UIView) -> RefenceView(UIView) -> LabelMakingView(UIView) -> StackView(UIView) Having a Multiple Labels

When I try to apply a shadow and Opacity on the RootView which is CTStickerView at that time will look good as mentioned in screenshot_1 and after that at the time of exporting the view there but something went wrong and I get the output as attached in screenshot_2.

enter image description here

enter image description here

Shadow Code:

extension UIView {
    func addShadowOnStickerView(ofColor color: UIColor = UIColor(red: 0.07, green: 0.47, blue: 0.57, alpha: 1.0), radius: CGFloat = 3, offset: CGSize = .zero, opacity: Float = 0.5, rangeMultiplier : CGFloat = 1.0) {
        layer.shadowColor = color.cgColor
        layer.shadowOffset = offset
        layer.shadowRadius = radius * rangeMultiplier
        layer.shadowOpacity = opacity
        layer.masksToBounds = false
        layer.zPosition = 0
    }
}

Opacity Code:

self.alpha = opacity

Caller:

fileprivate func applyShadow() {
    self.addShadowOnStickerView(ofColor: defaultShadowColor, radius: _shadow, offset: .zero, opacity: Float(((_shadow == 0) ? 0.0 : _opacity)), rangeMultiplier: 4.0)
}

fileprivate func applyOpacity() {
    self.alpha = opacity
}

Note if I apply Only shadow OR Opacity at that it will work perfectly as needed.

Really appreciated it, incase if I will get any help gets from the StackOverflow community.

Thanks in advance.

0

There are 0 answers