2016-01-28 3 views
4

Я создал прямоугольник, используя следующий код, и теперь мне нужно закруглить углы этого прямоугольника. но я не могу найти свойство, называемое layer.cornerRadius, может ли кто-нибудь мне помочь?Как дать cornerRadius для UIBezierPath

class OvalLayer: CAShapeLayer { 

    let animationDuration: CFTimeInterval = 0.3 

    override init() { 
     super.init() 
     fillColor = Colors.green.CGColor 
     path = ovalPathSmall.CGPath 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 
var ovalPathStart: UIBezierPath { 
     let path = UIBezierPath(ovalInRect: CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)) 

     return path 
    } 
} 
+0

и можно использовать сам UIBezierPath во время рисования, чтобы радиус закругления – vaibby

+0

Поскольку вы используете ** UIBezierPath ** вам нужно нарисовать округленный угол, используя только UIBezierPath. Проверьте [this] (http://ronnqvi.st/thinking-like-a-bzier-path/), это поможет вам в этом. – iphonic

ответ

6

Вы можете использовать ниже метод, чтобы сделать все угловой раунд зрения ...

UIBezierPath(roundedRect: anyView.bounds, cornerRadius: CGSize(width: 10.0, height: 10.0)) 

Если вы хотите конкретный угол, чтобы сделать круглое использование ниже метода.

UIBezierPath(roundedRect: anyView.bounds, 
     byRoundingCorners: .BottomLeft | .BottomRight, 
     cornerRadius: CGSize(width: 10.0, height: 10.0)) 
+1

вы можете предложить закругленные углы для пользовательских фигур, таких как звезда. –

1

Objective C:

UIBezierPath* path = [UIBezierPath 
    bezierPathWithRoundedRect: CGRectMake(0, 0, 150, 153) 
       cornerRadius: 50]; 

СВИФТ:

var path: UIBezierPath = UIBezierPath(roundedRect: CGRectMake(0, 0, 150, 153), cornerRadius: 50) 

Надеется, что это поможет.

2

использование этого инициализатора

let path1 = UIBezierPath(roundedRect: CGRect, cornerRadius: CGFloat) 

или

let path1 = UIBezierPath(roundedRect: CGRect, byRoundingCorners: UIRectCorner, cornerRadii: CGSize)) 
6

использовать так:

let pathWithRadius = UIBezierPath(roundedRect:yourView.bounds, byRoundingCorners:[.TopRight, .TopLeft], cornerRadii: CGSizeMake(5.0, 5.0)) 
let maskLayer = CAShapeLayer() 
maskLayer.pathWithRadius = pathWithRadius.CGPath 
yourView.layer.mask = maskLayer 

для всех Corner Radius редактировать этот

[.TopRight,.TopLeft,.BottomRight, .BottomLeft]