iphone – 如何检查UILabel文本是否被触动?

iphone – 如何检查UILabel文本是否被触动?,第1张

概述我想检查我的UILabel是否被触动.但我需要甚至更多.文字是否触动?现在我只有使用这个UILabel框架才能得到真/假: - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; if (CGRectCont 我想检查我的UILabel是否被触动.但我需要甚至更多.文字是否触动?现在我只有使用这个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内的信件外面的某个地方,我想要虚假的返回.

我想知道什么时候实际的黑色渲染“文字像素”已被触动.

谢谢!

解决方法 根据我的理解,问题是检测在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文本是否被触动?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1085100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存