2016-01-22 4 views
2

Я добавил следующие строки кода:Как изменить цвет фона UIBezierPath?

var radius: CGFloat = UIScreen.mainScreen().bounds.width - 60 
    let path: UIBezierPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height), cornerRadius: 0) 

    let circlePath: UIBezierPath = UIBezierPath(roundedRect: CGRect(x: 30, y: (UIScreen.mainScreen().bounds.height - radius)/2 - (navigationController?.navigationBar.frame.height)!, width: radius, height: radius), cornerRadius: radius) 

    path.appendPath(circlePath) 

, но это дает мне этот результат

enter image description here

Как я могу сделать мой круг цвет фона - clearColor()?

Я попытался это одно:

UIColor.whiteColor().setFill() 
circlePath.fill() 

Но это не имеет никакого смысла

+0

Почему это не имеет никакого смысла? –

+0

@ A-Live, это то, что я хочу знать :) –

ответ

5

Попробуйте это,

 var radius: CGFloat = 50 
     let path: UIBezierPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 50, height: 50), cornerRadius: 0) 

     let circlePath: UIBezierPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: radius, height: radius), cornerRadius: radius) 

     path.appendPath(circlePath) 

     let fillLayer = CAShapeLayer(); 
     fillLayer.path = path.CGPath; 
     fillLayer.fillColor = UIColor.redColor().CGColor; 
     yourView.layer.addSublayer(fillLayer) 

Путь делает нет цвет, слой есть цвет. Вам необходимо создать слой, основанный на пути, и добавить его в слой вашего представления, как описано выше.

+0

он работает! Благодаря! –

+0

Добро пожаловать.! наслаждайтесь программированием в быстром –

+0

он работает! Благодаря! – Marin

0

попробовать это:

let context = UIGraphicsGetCurrentContext(); 

CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor); 
+0

ничего не изменилось –

+0

Call circlePath.fill() наконец –

+0

Хотя это может ответить на вопрос, было бы лучше, если бы вы могли дать небольшое объяснение, почему оно это делает. –

Смежные вопросы