Bibi's DevLog ๐Ÿค“๐ŸŽ

TIL - 220428 : StackView์˜ subviews ์ง€์šฐ๊ธฐ - .subviews, .arrangedSubviews, .removeArrangedSubview ๋ณธ๋ฌธ

TIL

TIL - 220428 : StackView์˜ subviews ์ง€์šฐ๊ธฐ - .subviews, .arrangedSubviews, .removeArrangedSubview

๋น„๋น„ bibi 2022. 4. 29. 00:30

220428


StackView์˜ subviews ์ง€์šฐ๊ธฐ - .subviews, .arrangedSubviews, .removeArrangedSubview

if badgeStackView.subviews.count != .zero {
   badgeStackView.clearSubviews() // ์•„๋ž˜ ์ต์Šคํ…์…˜ ์ฐธ๊ณ 
}

์•„๋ž˜์™€ ๊ฐ™์ด UIStackView์— ์ต์Šคํ…์…˜์œผ๋กœ ๋งŒ๋“ค์–ด ๋‘๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ํŽธํ•จ.

import Foundation
import UIKit

extension UIStackView {
    func clearSubviews() {
        self.arrangedSubviews.forEach { view in
            self.removeArrangedSubview(view) // ๋ถ€๋ชจ๋ทฐ์—์„œ๋„ ์ž์‹ ๋ทฐ๋ฅผ ์ง€์›Œ์ฃผ๊ณ 
            view.removeFromSuperview() // ์ž์‹ ๋ทฐ์—์„œ๋„ ๋ถ€๋ชจ ๋ทฐ๋ฅผ ์ง€์›Œ์ค€๋‹ค
        }
    }
}

'TIL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[TIL] 2021๋…„ 6์›”  (0) 2021.06.30
[TIL] 2021๋…„ 5์›”์ž TIL  (0) 2021.06.02
[TIL] 2021๋…„ 4์›” TIL  (0) 2021.05.01
[TIL] 2021๋…„ 3์›” TIL  (0) 2021.04.06
[TIL - 210302~210307]  (0) 2021.03.08