728x90
함수 사용
textLabel.textColor = convertDiffColor(dif: money)
func convertDiffColor(dif: Double) -> UIColor {
guard dif > 0 else { return .systemBlue }
return .systemRed
}
double타입인 money를 인자로 받아 연산하여 textColor을 변환한다.
0보다 크면 systemRed를, 0보다 작으면 .systemBlue로 표시한다.
삼항연산자 사용
diffLabel.textColor = stock.diff > 0 ? .systemRed : .systemBlue
// (조건) ? (true일때) : (false일때)
728x90
'🍎 Apple > Swift' 카테고리의 다른 글
[Swift] Property Wrapper (0) | 2023.04.23 |
---|---|
싱글톤 사용 시 private init() 하는 이유 (0) | 2022.11.21 |
[Swift] list 정렬 (0) | 2022.10.13 |
[Swift] DateFormatter을 사용하여 string을 date형식으로 변환하기 (0) | 2022.10.13 |
[Swift] 정수 값 화폐 단위로 변환(3자리수 마다 컴마찍기) (0) | 2022.10.11 |