- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ UItouch *touch = [[event alltouches] anyObject]; if (CGRectContainsPoint([self.currentLetter frame],[touch locationInVIEw:self.vIEw])) { NSLog(@"HIT!"); }}
有没有办法检查这个?一旦我触摸到UILabel内的信件外面的某个地方,我想要虚假的返回.
我想知道什么时候实际的黑色渲染“文字像素”已被触动.
谢谢!
解决方法 根据我的理解,问题是检测在UILabel中组成文本的字形之间发生点击(触摸)的时间.如果触摸位于任何字形的路径之外,则不计入.这是我的解决方案它假定一个名为_label的UILabel * ivar和一个与包含标签的视图关联的UITapGestureRecognizer.
- (IBAction) ontouch: (UITapGestureRecognizer*) tgr{ CGPoint p = [tgr locationInVIEw: _label]; // in case the background of the label isn't transparent... UIcolor* labelBackgroundcolor = _label.backgroundcolor; _label.backgroundcolor = [UIcolor clearcolor]; // get a UIImage of the label UIGraphicsBeginImageContext( _label.bounds.size ); CGContextRef c = UIGraphicsGetCurrentContext(); [_label.layer renderInContext: c]; UIImage* i = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); // restore the label's background... _label.backgroundcolor = labelBackgroundcolor; // draw the pixel we're interested in into a 1x1 bitmap unsigned char pixel = 0x00; c = CGBitmapContextCreate(&pixel,1,8,NulL,kCGImageAlphaOnly); UIGraphicsPushContext(c); [i drawAtPoint: CGPointMake(-p.x,-p.y)]; UIGraphicsPopContext(); CGContextRelease(c); if ( pixel != 0 ) { NSLog( @"touched text" ); }}总结
以上是内存溢出为你收集整理的iphone – 如何检查UILabel文本是否被触动?全部内容,希望文章能够帮你解决iphone – 如何检查UILabel文本是否被触动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)