2010-12-01 17 views
34

A causa di UIProgressHUD necessario accedere a private API, quindi spero di costruire un UIView con angolo rotondo e bordo bianco. che conosco per fare il giro angolo è:UIView con angolo rotondo e bordo bianco

view.layer.cornerRadius = 5; 

Ma come fare l'UIView ha dell'angolo rotondo e bordo bianco, allo stesso tempo?

favore qualsiasi commento

Grazie InterDev

risposta

75

Utilizzando lo stesso oggetto strato:

view.layer.borderWidth = 1; 
view.layer.borderColor = [[UIColor whiteColor] CGColor]; 
11

Ci sono proprietà dei bordi nello strato della vista così: per esempio:

view.layer.borderWidth = 1; 
view.layer.borderColor = [UIColor redColor].CGColor; 
+2

CALayer fa parte di Core Animation, non di UIKit. Pertanto, prende un CGColor, non UIColor. – MarkPowell

+1

Oh sì, scusa, stavo scrivendo quello dalla mia testa. –

0
[view.layer setBorderWidth:2]; 

[view.layer setBorderColor:[[UIColor whiteColor]CGColor]]; 
4

codice per ottenere angoli arrotondati e bordo

#import <QuartzCore/QuartzCore.h> 
view.layer.cornerRadius = 10; 
view.layer.borderWidth = 1; 
view.layer.borderColor = [[UIColor whiteColor] CGColor]; 
6

volte raggio d'angolo con bordo bianco non funziona correttamente per cui uso UIBezierPath e CAShapeLayer.

Per rendere il raggio d'angolo

UIBezierPath *maskPath; 
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)]; 

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame = self.view.bounds; 
maskLayer.path = maskPath.CGPath; 
self.imageView.layer.mask = maskLayer; 

Per rendere il bordo bianco

CAShapeLayer* borderShape = [CAShapeLayer layer]; 
borderShape.frame = self.imageView.bounds; 
borderShape.path = maskPath.CGPath; 
borderShape.strokeColor = [UIColor whiteColor].CGColor; 
borderShape.fillColor = nil; 
borderShape.lineWidth = 3; 
[self.imageView.layer addSublayer:borderShape]; 

Funzionerà. Spero che questo aiuto

+1

L'uso di .cornerRadius, .borderWidth e .borderColor insieme a .clipsToBounds mi ha dato un artefatto attorno a imageView quando volevo un'immagine rotonda con un bordo bianco. Questo ha risolto il problema per me. – Undrea

5
view.layer.cornerRadius = 5; 
view.clipsToBounds = YES; 
view.layer.borderWidth = 1; 
view.layer.borderColor = [UIColor whiteColor].CGColor; 
Problemi correlati