ABTableViewCell - 添加UIButton [英] ABTableViewCell - Adding a UIButton

查看:115
本文介绍了ABTableViewCell - 添加UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用ABTableViewCell来创建快速滚动单元格。一切都很好,除了我无法弄清楚如何将UIButton添加到我的自定义单元格。

I have been using the ABTableViewCell to create fast scrolling cells. All is working great apart from I can't figure out how to add a UIButton to my custom cell.

使用ABTableViewCell时,您可以完成所有文本/图像的绘制你自己使用drawAtPoint或drawInRect。但是,UIButton不支持任何这些方法。你无法做addSubView因为使用ABTableViewCell只是你只有一个视图。

When using ABTableViewCell you do all the drawing of the text/images yourself using drawAtPoint or drawInRect. However UIButton doesn't support any of these methods. You can't do addSubView as the whole point of using ABTableViewCell is that you only have one view.

任何人都知道如何做到这一点?

Anyone had any idea of how to do this?

谢谢

推荐答案

我在ABTableViewCell sublcass中有一个分享按钮。

I have a "share" button inside a ABTableViewCell sublcass.

   static UIImage* imgShare=nil;
    + (void)initialize
    {
        if(self == [MyCustomCell class])
        {
            imgShare = [[UIImage imageNamed:@"share.png"] retain];      
        }
    } 

我使用黄色矩形首次亮相活动区域按钮。
在drawRect回调中:

I use a yellow rect to debut the active area of the button. In drawRect callback:

CGRect btnShareActiveAreaRect;
    - (void)drawContentView:(CGRect)r
    {
        [[UIColor yellowColor] set];
        btnShareActiveAreaRect = CGRectMake(10,10,65,45);
        CGContextFillRect(context, btnShareActiveAreaRect);
        CGRect shareRect = CGRectMake(15,20,25,19);
        [imgShare drawInRect:shareRect];
    }

处理触摸:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch =[touches anyObject]; 
    CGPoint startPoint =[touch locationInView:self.contentView];
    if(CGRectContainsPoint(btnShareActiveAreaRect,startPoint))
    {
        [self shareButton_Click];
    }
    else
        [super touchesBegan:touches withEvent:event];
}

这篇关于ABTableViewCell - 添加UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆