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

Image Rendering Mode #31

Closed
Taehyeon-Kim opened this issue Jul 11, 2022 · 1 comment
Closed

Image Rendering Mode #31

Taehyeon-Kim opened this issue Jul 11, 2022 · 1 comment
Assignees

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Jul 11, 2022

Original Image vs Template Image

tintColor

UIImageView - Instance Property
뷰 계층에서 템플릿 이미지에 색조를 지정하는데 사용되는 컬러입니다.

var tintColor: UIColor! { get set }

default는 nil입니다. 만약 nil이 아니라면 컬러는 이미지 뷰에 첨부된 템플릿 이미지에 적용됩니다. 기본적으로 tintColor는 UIView가 가지고 있는 프로퍼티입니다. 상위가 되는 뷰의 tintColor를 변경하면 상속받는 하위 뷰에 차례대로 영향을 줄 수 있습니다.

override func viewDidLoad() {
    view.tintColor = UIColor.red
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window?.tintColor = UIColor.red

    return true
}

UIImage.RenderingMode

이미지에 대해 가능한 렌더링 모드를 지정하는 상수입니다.

  • Enumeration (열거형)
enum RenderingMode : Int, @unchecked Sendable

렌더링 모드는 UIKit이 색상 정보를 사용하여 이미지를 표시하는 방법을 제어합니다. 렌더링 모드의 디폴트는 automatic입니다.

Original Image

case alwaysOriginal
let image = UIImage(named: "")?.withRenderingMode(. alwaysOriginal)
  • 항상 원본 이미지를 그대로 사용해서 그립니다. (원본 색상을 사용합니다.)

Template Image

case alwaysTemplate
let image = UIImage(named: "")?.withRenderingMode(.alwaysTemplate)
  • 이미지의 색상 정보를 무시하고 템플릿 이미지로 그립니다.
  • 원본 이미지가 가지고 있는 컬러정보는 무시하고 지정한 tintColor로 색상이 적용됩니다.
  • tintColor가 적용되는 부분은 이미지의 불투명한 부분입니다.

Asset에서 Rendering Mode를 직접 변경하는 방법

스크린샷 2022-07-12 오전 10 24 58

정리

이미지의 색상을 임의의 값으로 변경하고 싶다면 Rendering Mode를 .alwaysTemplate으로 변경하고 tintColor를 조정하면 됩니다.

@Taehyeon-Kim Taehyeon-Kim self-assigned this Jul 11, 2022
@Taehyeon-Kim Taehyeon-Kim changed the title 이미지 Rendering Mode Image Rendering Mode Jul 11, 2022
@Taehyeon-Kim
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant