Ich arbeite in Swift 3.0 und habe UIBezierPath verwendet, um Kreise zu zeichnen. Mein Code ist unten. Egal, was ich ändere, die Ränder des Kreises sind immer noch abgeschnitten. Die Kreise sind in Bildansichten. Ich habe versucht, die Höhe/das Gewicht der Ansicht zu manipulieren, sowie es zu ändern "aspect fill" "aspect fit" "center" usw. Ein Tutorial habe ich mir auch gesagt, wenn ich "var multiplier: CG Float = 1.0 "bis 0.85 oder eine andere Nummer, wird der Ausschnitt weg sein. Ich habe das versucht und es hat nicht funktioniert. Wie kann ich das beheben?Kreise in Swift - kann nicht von Clipping loswerden
class Circle1: UIView {
var multiplier:CGFloat = 0.85
//this takes away the "clippinh" you might see in the view
var centerOfCirclesView: CGPoint{
return CGPoint(x:bounds.midX, y:bounds.midY)
}
var halfOfViewsSize: CGFloat{
return min(bounds.size.height, bounds.size.width)/2
}
var lineWidth:CGFloat = 1.0
//circle radius compute
var full = CGFloat(M_PI * 2)
var quarter = CGFloat(M_PI/2)
var half = CGFloat(M_PI)
var threeQuarters = CGFloat(3 * M_PI/2)
func drawCircleCenteredAt(_:CGPoint, withRadius radius:CGFloat) -> UIBezierPath{
let circlePath = UIBezierPath(arcCenter: centerOfCirclesView,
radius: halfOfViewsSize,
startAngle: 00,
endAngle: full,
clockwise: false)
circlePath.lineWidth = lineWidth
return circlePath
}
override func draw(_ rect: CGRect) {
UIColor(hue: 0.7194, saturation: 0, brightness: 0.52, alpha: 1.0).set()
lineWidth = 15.0
drawCircleCenteredAt(centerOfCirclesView, withRadius: halfOfViewsSize).stroke()
}
}
class Circle2: UIView {
var multiplier:CGFloat = 0.85
//this takes away the "clippinh" you might see in the view
var centerOfCirclesView: CGPoint{
return CGPoint(x:bounds.midX, y:bounds.midY)
}
var halfOfViewsSize: CGFloat{
return min(bounds.size.height, bounds.size.width)/2
}
var lineWidth:CGFloat = 1.0
//circle radius compute
var full = CGFloat(M_PI * 2)
var quarter = CGFloat(M_PI/2)
var half = CGFloat(M_PI)
var threeQuarters = CGFloat(3 * M_PI/2)
func drawCircleCenteredAt(_:CGPoint, withRadius radius:CGFloat) -> UIBezierPath{
let circlePath = UIBezierPath(arcCenter: centerOfCirclesView,
radius: halfOfViewsSize,
startAngle: 00,
endAngle: half,
clockwise: false)
circlePath.lineWidth = lineWidth
return circlePath
}
}
Sie benötigen Radius zu vermindern, dass entweder durch Ihre 0,85 Multiplikator multipliziert oder um 0,5 * Linienbreite subtrahiert wird. – vacawama
Sie sollten '.pi' anstelle von' M_PI' in Swift 3 –