Sto provando a creare un'etichetta (o qualsiasi altra vista per quella materia) con un angolo arrotondato e un tratto/bordo. Posso raggiungere l'ex utilizzando il seguente codice:CALayer con mascheratura a tratto in iOS
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(16.0f, 16.0f)];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = self.label.bounds;
shape.path = maskPath.CGPath;
self.label.layer.mask = shape;
Quali grandi opere per l'angolo arrotondato, ma utilizzando il seguente codice non si applica la corsa nel modo desiderato. Invece di produrre un nero (o qualunque sia il backgroundColor
di self.label
impostato su) confine quadrato.
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(16.0f, 16.0f)];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = self.label.bounds;
shape.path = maskPath.CGPath;
// Add stroke
shape.borderWidth = 1.0f;
shape.borderColor = [UIColor whiteColor].CGColor;
self.label.backgroundColor = [UIColor blackColor];
self.label.layer.mask = shape;
Qualche suggerimento su come applicare un tratto colorato arbitrario che segue il percorso mascherato?
Questo genere di opere, ma ora il il testo dell'etichetta è stato coperto dal livello 'shape' :( –
OK Sono riuscito a farlo funzionare applicando la maschera ad un' UIView' e aggiungendo il 'UILabel' come sottoview.Grazie mille :) –
StrokeLayer copre l'etichetta quindi l'ho aggiunta per risolvere il problema 'shape.fillColor = [UIColor clearColor] .CGColor' –