Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- TEST
- Gradle
- MiTweet
- livedata
- android
- boj
- Kotlin
- Codeforces
- GitHub
- Compose
- 프로그래머스
- textfield
- 쿠링
- MyVoca
- Rxjava
- 코드포스
- AWS
- ProGuard
- Hilt
- Coroutines
- 암호학
- relay
- activity
- 백준
- Python
- Coroutine
- androidStudio
- 코루틴
- pandas
- architecture
Archives
- Today
- Total
이동식 저장소
Icon vs. Image 본문
(내가) 자주 실수하는 ``Icon``과 ``Image``! 어떻게 다른지 비교해 보자.
Icon
주로 단색 아이콘을 보여줄 때 사용한다. Material 아이콘 또는 벡터 drawable 등을 사용할 수 있으며, 아이콘에 적절한 색깔을 tint로 입혀 사용한다. 색깔을 입히고 싶지 않다면 ``Color.Unspecified``를 사용하면 된다.
@Composable
fun Icon(
painter: Painter,
contentDescription: String?,
modifier: Modifier = Modifier,
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
)
``contentDescription`` 매개변수를 통해 아이콘의 의미를 설명할 수 있다. 접근성을 보장하기 위해 가급적 설명을 추가하는 것이 좋다.
클릭 가능한 아이콘을 나타내려면 ``IconButton``을 사용하면 된다.
Image
이미지를 있는 그대로 보여줄 때 사용한다. 이미지의 크기는 이미지 파일의 크기를 기본값으로 사용하지만, ``Modifier``나 다른 constraint에 의해 달라질 수 있다.
비트맵 이미지와 벡터 이미지 모두 ``painterResource()`` API로 불러올 수 있다. 커스텀이 필요한 경우에는 각각 ``ImageBitmap.imageResource()``와 ``ImageVector.vectorResource()`` API를 활용하면 된다.
@Composable
fun Image(
painter: Painter,
contentDescription: String?,
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Fit,
alpha: Float = DefaultAlpha,
colorFilter: ColorFilter? = null
)
``Icon``과 마찬가지로 ``contentDescription`` 매개변수를 통해 이미지의 내용을 설명할 수 있다.
``colorFilter`` 매개변수를 사용하면 이미지의 톤을 다양하게 변조할 수 있다. 자세한 내용은 아래 링크를 참고하면 된다.
정리
- ``Icon``은 작은 단색 아이콘을 보여줄 때 사용한다. 상황에 따라 tint를 입힐 수 있다.
- ``Image``는 비트맵 또는 벡터 이미지를 보여줄 때 사용한다.
헷갈리지 말 것!
'Primary > Compose' 카테고리의 다른 글
Modifier로 블러 효과 구현하기 (0) | 2024.05.01 |
---|---|
Compose TextField를 커스터마이징해 보자 (0) | 2024.04.30 |
Compose에서 시스템 폰트 크기 확인하기 (0) | 2024.03.24 |
TextField에 default string을 줘도 커서가 맨 앞으로 가는 이유 (2) | 2024.02.28 |
Compose에서 Icon의 크기를 IconButton만큼 키우고 싶다면? (0) | 2024.02.06 |
Comments