निम्न छवि पर एक नज़र डालें:UIButton नियंत्रण से तेज आयताकार किनारों को कैसे निकालें?
आप किनारों तेज आयत हैं और वे गोल कोने बटन के बाहर आ रहे हैं देख सकते हैं। मैं किनारों को कैसे दिखा सकता हूं और केवल गोल बटन दिखा सकता हूं?
अद्यतन (समाधान):
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.stopButton.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(12.0, 12.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.stopButton.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.stopButton.layer.mask = maskLayer;
नई समस्या:
इस कोड को मुझे startButtonRound.layer पर त्रुटि देता है
मैं दौर कोनों को प्राप्त करने के लिए निम्न कोड का इस्तेमाल किया। कोनेराइडियस लाइन।
UIButton *roundStartButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
roundStartButton.frame = CGRectMake(10, 10, 100, 20);
[roundStartButton setBackgroundImage:[UIImage imageNamed:@"green_gradient.jpg"] forState:UIControlStateNormal];
roundStartButton.layer.cornerRadius = 12.0;
UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithCustomView:roundStartButton];
मैंने कोशिश की [बटन परत] सेटकॉर्नर रेडियस: 5.0 एफ]; लेकिन इसका बटन पर कोई प्रभाव नहीं पड़ा। – azamsharp
गोलाकार कोनों को अपनी सामग्री को क्लिप करने के लिए परत प्राप्त करने के लिए आपको मास्क टॉबाउंड्स को हां में सेट करने की आवश्यकता हो सकती है। –
क्या यूआईबटन को काम करने के लिए कोनेडियस के लिए आईबीओलेट के रूप में घोषित किया जाना है? मूल पोस्ट अद्यतन समस्या देखें। – azamsharp