如何在不初始化gestureRecognizer.view标签的情况下找出点击的标签

时间:2014-04-27 20:40:01

标签: ios objective-c

我的ios应用程序中有标签可以响应轻击手势。为了更改被点击的标签的属性,我通过执行此操作找出了哪个标签

CustomLabel * label = gestureRecognizer.view;

然后相应地更改我希望的属性。但是,上面的代码行会发出警告

incompatible pointer type initializing CustomLabel with an expression of type UIView

在没有收到警告的情况下,这样做的正确方法是什么?

-(void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state != UIGestureRecognizerStateEnded)
        return;

    CustomLabel * label = gestureRecognizer.view;
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor greenColor];

0 个答案:

没有答案