HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 如何检查UILabel文本是否被触动?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想检查我的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文本是否被触动?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。