如何繪製像圖像的視圖下方與貝塞爾曲線繪製的UIView
我想的UIView像圖片標註視圖,
我知道,從設計師獲得圖像和它分配UIImageView,我不想這樣做,彈出演示也沒有必要。
我希望通過 UIBezierPath 或其他一些其他的方式與UIView的做到這一點..
幫助將提前讚賞和感謝!
如何繪製像圖像的視圖下方與貝塞爾曲線繪製的UIView
我想的UIView像圖片標註視圖,
我知道,從設計師獲得圖像和它分配UIImageView,我不想這樣做,彈出演示也沒有必要。
我希望通過 UIBezierPath 或其他一些其他的方式與UIView的做到這一點..
幫助將提前讚賞和感謝!
你可以試試這個:
class PopUpView: UIView {
override func draw(_ rect: CGRect) {
let width: CGFloat = rect.width
let height: CGFloat = rect.height
let radius: CGFloat = 8
let arrowRadius: CGFloat = 4
let arrowWidth: CGFloat = 24
let arrowHeight: CGFloat = 18
let startingPoint = CGPoint(x: radius, y: 0)
let upperRightCenter = CGPoint(x: width - radius, y: radius)
let bottomRightCenter = CGPoint(x: width - radius, y: height - radius - arrowHeight)
let bottomLeftCenter = CGPoint(x: radius, y: height - radius - arrowHeight)
let upperLeftCenter = CGPoint(x: radius, y: radius)
let path: UIBezierPath = UIBezierPath()
path.move(to: startingPoint)
path.addArc(withCenter: upperRightCenter, radius: radius, startAngle: 270.degreesToRadians, endAngle: 0, clockwise: true)
path.addArc(withCenter: bottomRightCenter, radius: radius, startAngle: 0, endAngle: 90.degreesToRadians, clockwise: true)
path.addArc(withCenter: CGPoint(x: (width + arrowWidth)/2 + arrowRadius, y: height + arrowRadius - arrowHeight), radius: arrowRadius, startAngle: 270.degreesToRadians, endAngle: 225.degreesToRadians, clockwise: false)
path.addArc(withCenter: CGPoint(x: width/2, y: height - arrowRadius), radius: arrowRadius, startAngle: 45.degreesToRadians, endAngle: 135.degreesToRadians, clockwise: true)
path.addArc(withCenter: CGPoint(x: (width - arrowWidth)/2 - arrowRadius, y: height + arrowRadius - arrowHeight), radius: arrowRadius, startAngle: 315.degreesToRadians, endAngle: 270.degreesToRadians, clockwise: false)
path.addArc(withCenter: bottomLeftCenter, radius: radius, startAngle: 90.degreesToRadians, endAngle: 180.degreesToRadians, clockwise: true)
path.addArc(withCenter: upperLeftCenter, radius: radius, startAngle: 180.degreesToRadians, endAngle: 270.degreesToRadians, clockwise: true)
path.close()
UIColor.gray.setFill()
UIColor.clear.setStroke()
path.fill()
path.stroke()
}
}
extension Int {
var degreesToRadians: CGFloat {
return CGFloat(M_PI) * CGFloat(self)/180.0
}
}
基本上我一個子類UIView的,overidden drawRect方法和使用UIBezierPath創建類似的形狀。您可能想要更改我用來滿足您的要求的值。
感謝您的回覆,我會盡力讓您知道 – karthikeyan
drawRect方法根本不會調用,您能向我們展示代碼的用法,或者我應該如何在控制器中調用類? – karthikeyan
@karthikeyan你只需要用PopUpView類繼承你的UIView。它在我的應用程序中工作。 – Aakash
4個角落使用bazer路徑倒圓角但不使用向下箭頭使用bazer路徑繪製 – Jay
因此您使用圖像向下箭頭 – Jay
這是可能的 – karthikeyan