아울렛 객체로 [UIView] 만들기
Youngminah opened this issue · 2 comments
Youngminah commented
아울렛 객체 컬렉션 만들기
@IBOutlet var collectionLabel: [UILabel]!
- 위처럼 선언이 가능하다.
- weak로는 선언 불가능하다고 오류 뜸 왜지? (밑에 답글 참고)
collectionLabel.forEach { $0.setBorderStyle() }
UILabel + Extension
import UIKit.UILabel
extension UILabel {
func setBorderStyle() {
self.backgroundColor = .systemTeal
self.clipsToBounds = true
self.layer.borderWidth = 1
self.layer.cornerRadius = 10
}
}
- 위의 코드의 장점
Youngminah commented
- 이걸 여태까지 모르고 있었음.. ㅠㅠ
Youngminah commented
IBOutletCollection은 weak로는 선언이 불가능함
- Outlet 하나는 class 참조 타입으로 선언이 되어있는데,
- OutletCollection의 컬렉션 형태로 만들면 구조체 타입이 된다.
- 따라서 구조체 타입이라 weak선언을 붙일 수 없다.