Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIView 에 그라데이션을 넣어보자 #55

Open
chaneeii opened this issue Oct 24, 2022 · 1 comment
Open

UIView 에 그라데이션을 넣어보자 #55

chaneeii opened this issue Oct 24, 2022 · 1 comment
Labels
UIKit UIKit

Comments

@chaneeii
Copy link
Owner

https://babbab2.tistory.com/55

@chaneeii
Copy link
Owner Author

gradient 코드

    private func setImageViewBackgroundGradient() {
        self.layoutIfNeeded()
        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.locations = [0.0, 1.0]
        let colors: [CGColor] = [
           .init(red: 0, green: 0, blue: 0, alpha: 0),
           .init(red: 0, green: 0, blue: 0, alpha: 1)
        ]
        gradient.colors = colors
        gradient.startPoint = CGPoint(x: 0.0, y: 0.71)
        gradient.endPoint = CGPoint(x: 0.0, y: 1.0)
        gradient.frame = .init(x: 0, y: 0,
                               width: self.reviewImageView.frame.width,
                               height: self.reviewImageView.frame.height)
        self.reviewImageView.layer.insertSublayer(gradient, at: 0)
    }

사용할때

사용하는 시점이 중요!
레이아웃잡을때

self.setImageViewBackgroundGradient()

@chaneeii chaneeii added the UIKit UIKit label Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UIKit UIKit
Projects
None yet
Development

No branches or pull requests

1 participant