카테고리 없음
swift 라벨 타이머 고정시키는 방법 알아보자
kingarthur
2024. 8. 27. 12:26
타이머 생성해서 라벨을 만들면
시간이 바뀔때마다 가지는 와이드 범위가 달라서 막 움직인다
그래서 고정하고 싶어서 찾다가 안되었는데 튜터님 추천 받은 사이트에서 바로 문제 해결!
label.font = UIFont.monospacedSystemFont(ofSize: 100, weight: UIFont.Weight.bold)
label.font = UIFont(name: "Menlo-Regular", size: 105)
label.font = UIFont(name: "HelveticaNeue", size: 105)
여기 세가지 방식 중에서 채택해서 사용하면 된다.
아주아주 쉬웠지만 해결못한나...
아래 참고 사이트
iOS Prevent timer UILabel 'shaking' when numbers change
I have a UILabel which shows the output of a timer in the format MM:ss:SS (minutes, seconds, centiseconds), however it "shakes" from left to right as the width of the centiseconds changes - "11" is
stackoverflow.com
// 최대 너비를 계산하여 레이블의 너비를 고정합니다.
let maxWidthText = "88:88"
let fixedWidth = maxWidthText.width(font: .systemFont(ofSize: 110, weight: .bold)).ceiling(to: 1)
다른 구글링에서는 최대 넓이 고정값에 줘서 했다던데 난 안되서... 패스 했음요
아무튼 해결해서 기분이 쨰져~