Storyboard 오토레이아웃으로만 동적인 변화가 가능하게 만들기
빨간색 Label 영역 처리
늘어나는 Label 영역 처리
💡 초기 Hugging을 빨간 영역이 더 작아 늘어나는 Label이 남긴 부분을 자신의 Constraints Heights로 채운다. 하지만, 글자가 길어질 수록 Resistance 또한 빨간 영역이 더 작아 높이가 점점 더 작아진다.
전체 Constraints
Timer를 사용해서 0.5초마다 글을 추가했다.
let btnText = "ㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁㅁ"
var timer: Timer?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.timer = Timer.scheduledTimer(timeInterval: 0.5,target: self,selector: #selector(goTimer(timer:)),userInfo: nil,repeats: true)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.timer?.invalidate()
}
@objc func goTimer(timer:Timer){
self.idx = (self.idx + 1) % 6
var nextText = self.btnText
for _ in 0..<(self.idx + 1){
nextText += "ㅁ"
}
self.bottomLabel.text = nextText
print(nextText)
}
'이모저모 > UIKit' 카테고리의 다른 글
Modern UIKit Collection, TableView #2-1 (0) | 2023.09.03 |
---|---|
Modern UIKit Collection, TableView #1 (0) | 2023.08.25 |
WWDC) Customize and resize sheets in UIKit (0) | 2023.08.02 |
테이블 셀 내부 UIButton에 addTarget을 계속 해도 되는이유 (0) | 2023.08.01 |
UICollectionViewFlowLayout에 아이템간 간격을 주는 이유 (0) | 2023.07.31 |
댓글