Case 01 · 드로잉
본체와 꼬리를 나눠 그린다
말풍선은 본체(둥근 사각형)와 꼬리(삼각형)의 테두리가 한 획처럼 이어져 보여야 합니다. 점선 스타일까지 지원하려면 layer 테두리만으로는 부족합니다.
본체는 CAShapeLayer로 둥근 사각형과 점선을 그리고, 꼬리는 draw(_:)에서 UIBezierPath로 삼각형을 그렸습니다. 두 뷰는 테두리가 끊겨 보이지 않도록 borderWidth만큼 겹쳐 배치했습니다.
꼬리를 4방향(top/bottom/left/right) 어디든, 변의 임의 비율 위치에 붙일 수 있습니다. positionRatio로 기준점을 잡고 arrowSize만큼 벌려 그립니다.
ArrowView.swift
// 모서리 길이 x 비율로 기준점 case .top: pointTip = CGPoint(x: position, y: rect.height - arrowSize) pointLeft = CGPoint(x: position - arrowSize, y: rect.height) pointRight = CGPoint(x: position + arrowSize, y: rect.height) let path = UIBezierPath() path.move(to: arrowPoints.left) path.addLine(to: arrowPoints.tip) path.addLine(to: arrowPoints.right) if style.contains(.fill) { filledColor.setFill(); path.fill() }