मैं एक गोलाकार कोने और स्ट्रोक/सीमा के साथ एक लेबल (या उस मामले के लिए कोई अन्य दृश्य) बनाने की कोशिश कर रहा हूं। मैं निम्नलिखित कोड का उपयोग कर पूर्व प्राप्त कर सकते हैं:आईओएस में स्ट्रोक मास्क किए गए कैलियर
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;
कौन सा गोल कोने के लिए अच्छा काम करता है, लेकिन निम्नलिखित कोड का उपयोग कर स्ट्रोक तरह से मैं चाहता हूँ लागू नहीं होता। self.label
के को सेट करने के बजाय वर्ग सीमा के लिए एक काला (या जो भी backgroundColor
) सेट किया गया है।
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;
कैसे मैं एक मनमाना रंग स्ट्रोक कि नकाबपोश पथ का अनुसरण आवेदन कर सकते हैं पर कोई सुझाव?
यही काम करता है की तरह है, लेकिन अब लेबल का पाठ 'आकार' परत से ढका हुआ है :( –
ठीक है, मैंने इसे 'UIView' पर मुखौटा लगाने और' UILabel' को उप-दृश्य के रूप में जोड़कर काम करने में कामयाब रहा है। बहुत बहुत धन्यवाद :) –
स्ट्रोकलेयर लेबल को कवर करता है इसलिए मैंने इसे 'shape.fillColor = [UIColor clearcolor] को ठीक करने के लिए जोड़ा। .CGColor' –