I want to add button to the top-left corner of UICollectionViewCell
. I am able to add the button on top left of cell but it does not appear on top of the cell, but under the cell. Please tell me how can I do that ?
I am using below code:
_deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, delButtonSize, delButtonSize)];
_deleteButton.center = CGPointMake(9, 10);
_deleteButton.backgroundColor = [UIColor clearColor];
[_deleteButton setImage: [UIImage imageNamed:@"cross_30.png"] forState:UIControlStateNormal];
[cell addSubview:_deleteButton];
[_deleteButton addTarget:self action:@selector(deleteRecipe:) forControlEvents:UIControlEventTouchUpInside];
Edit:
I want to make delete icon like this:
Did you try adding it to the content view of the cell?
[cell.contentView addSubview:_deleteButton];
use bringSubviewToFront in UIView:
[cell bringSubviewToFront:_deleteButton];
reference: UIView bringSubviewToFront
to achieve the effect on the top left corner out of cell's bound, you should follow Islam Q's answer by move the deletebutton's frame outside of cell's bound, and set cell's clip subview to NO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With