मैं यह निर्धारित करने की कोशिश कर रहा हूं कि क्या UILabel को छुआ था और यदि ऐसा कुछ है। दें ..मैं कैसे निर्धारित कर सकता हूं कि UILabel को छुआ था या नहीं?
.
.
.
UILabel * site = [[UILabel alloc] initWithFrame:CGRectMake(0, 185, 320, 30)];
site.text = [retriever.plistDict valueForKey:@"url"];
site.textAlignment =UITextAlignmentCenter;
site.backgroundColor = [UIColor clearColor];
site.textColor = [UIColor whiteColor];
site.userInteractionEnabled = YES;
[theBgView addSubview:site];
[site release];
.
.
.
फिर मैं कॉलबैक लिखता हूं।
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
retriever = [PListRetriever sharedInstance];
CGPoint pt = [[touches anyObject] locationInView: self];
NSURL *target = [[NSURL alloc] initWithString:[retriever.plistDict valueForKey:@"url"]];
[[UIApplication sharedApplication] openURL:target];
}
समस्या अभी ठीक है, इससे कोई फर्क नहीं पड़ता कि मैं यूआरएल को कैसे खोल रहा हूं। मैं कैसे निर्धारित करूं कि केवल मेरा लेबल छुआ था? अन्यथा
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.site frame], [touch locationInView:self.view]))
{
NSURL *target = [[NSURL alloc] ...];
...
}
}
इसके अलावा, मत भूलना यूआरएल आप आवंटित जारी करने के लिए (:
आप अपने लेबल को बटन के साथ क्यों नहीं बदलते? – zonble