2011-12-23 13 views
9

मैंने स्क्रीन पर प्रदर्शित करने के लिए प्रोग्रामेटिक रूप से लेबल के कुछ सेट बनाए हैं और मुझे लेबल पर क्लिक करने के बाद कुछ क्रियाएं करना चाहिए।आईफोन में UILabel पर कार्रवाई

कृपया मुझे UIButton के बारे में सुझाव न दें। मैं इसे UILabel के लिए करना चाहता हूँ। लेबल पर क्लिक करने के बाद एक और विवरण दृश्य दिखाना चाहिए।

कृपया इंटीफेस बिल्डर का उपयोग किये बिना इस समस्या को हल करने में मेरी सहायता करें।

+1

क्या UIButton साथ गलत क्या है? मुझे लगता है कि एक पारदर्शी UIbutton के पास आप जो चाहते हैं उसके साथ कुछ भी अलग नहीं है। – Skyler

उत्तर

22

प्रयास करें अंत में मैं आया समाधान के साथ और मुझे परिणाम मिला

[titleLbl setUserInteractionEnabled:YES]; 
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)]; 
    [tapGestureRecognizer setNumberOfTapsRequired:1]; 
    [titleLbl addGestureRecognizer:tapGestureRecognizer]; 
    [tapGestureRecognizer release]; 
4

अपने लेबल के IBoutlet बनाने, अपने नियंत्रक में touchesBegin लागू बाहर खींच CGPoint, -, touchCoordinate जाँच

CGRectContainsPoint(label.frame,touchCoordinate) 
{ 
//you got the touch action on your label 
} 
+1

कृपया मुझे आईबी –

+1

के बिना बताएं इसे बनाते समय अपने लेबल का टैग सेट करें: मान लीजिए कि आपने टैग सेट किया है: 199। फिर, जब भी आपको UILabel * लेबल = [self.view viewWithTag: 199] द्वारा लेबल की आवश्यकता होती है तो आप लेबल ला सकते हैं; – samfisher

+1

आप ऊपर दिए गए आईबीओलेट के बिना लेबल की ऑब्जेक्ट ला सकते हैं। मुझे आशा है कि यह मदद मिलेगी .. – samfisher

3

में

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
....... 
....... 
CGPoint touch;//Touch Location 

if(CGRectContainsPoint([objectOfLable frame], [touch locationInView:self.view ])) 
{ 
    Do What you Want 
} 

} 

यह