# 이걸 왜 공부하게 되었나요?

앱잼 데모데이 때 사람들이 약관동의 버튼의 터치 영역이 작아서 터치에 어려움을 겪는 것을 보고 터치 영역을 늘려야겠다고 공부하기로 생각했다.

# 공부한 내용 정리하기

1. UIView에서 사용하고 있는 point(inside: with)메소드를 override하여 touch 영역 확대

Untitled

2. touch 영역 확대는 bounds값을 계산하는 insetBy(dx:dy:)를 이용

Untitled

BaseButton 코드

class BaseButton: UIButton {
    override init(frame: CGRect) {
        super.init(frame: frame)

        configure()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        super.point(inside: point, with: event)

        /// 모든 방향에 20만큼 터치 영역 증가
        /// dx: x축이 dx만큼 증가 (음수여야 증가)
        let touchArea = bounds.insetBy(dx: -20, dy: -20)
        return touchArea.contains(point)
    }

    func configure() {}
    func bind() {}
}

# 오늘의 질문