大佬教程收集整理的这篇文章主要介绍了iphone – 如何检查UILabel文本是否被触动?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; if (CGRectContainsPoint([self.currentLetter frame],[touch LOCATIOnInView:self.view])) { NSLog(@"HIT!"); } }
有没有办法检查这个?一旦我触摸到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文本是否被触动?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。