开发者

Adding an overlay to a grid tableView

I have a tableview which each row has 4 images. I have implemented a share option which will allow the user to select multiple images. How can I add开发者_高级运维 an overlay or some kind of visual effect to show that the image is selected?

Adding an overlay to a grid tableView

I would like to add some overlay to display that an image is selected, but How would this be done without adding a new set of subview for each thumbnail? And once that is done, how would the selection of the new views be linked back to the images behind them so that they can be added to an array?

Or is there an easier way to do this?

Thanks


Depending on how you're implementing this grid view, it might make sense to track all of the selecting and deselecting at that level.

As for the overlay, the quick and dirty way is to subclass UIImageView, add a BOOL property called selected. Then you can override the setter for selected and handle showing or hiding your overlay view.

Here's how I would setup my subclass. First the interface:

@interface SelectableImageView : UIImageView

@property (nonatomic, assign, getter = isSelected) BOOL selected;

@end

and the implementation...

@interface SelectableImageView ()

@property (nonatomic, retain) UIView *overlayView;

@end



@implementation SelectableImageView

@synthesize selected;
@synthesize overlayView;

- (id)initWithFrame:(CGRect)frame
{    
    if (self = [super initWithFrame:frame])
    {
        overlayView = [[UIView alloc] initWithFrame:frame];
        overlayView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.75];
        overlayView.hidden = YES;
        [self addSubview:overlayView];
    }

    return self;
}

- (void)setSelected:(BOOL)flag
{
    selected = flag;
    self.overlayView.hidden = !flag;
}

- (void)dealloc
{
    [overlayView release], self.overlayView = nil;
    [super dealloc];
}

@end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜