UITableViewRowAction with image instead of title
Asked Answered
J

1

7

I'd like to make a cell swipe action like mail app.

I set UIImage to backgroundColor of row action.

 action.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"remove"]];

But i get my image repeated side-by-side on the background. like this.

Is the image size problem? Could tell me how to fix it,or an other way to do it ?

Jeremy answered 26/5, 2016 at 2:28 Comment(3)
Can you post the code at cellForRowAtIndexPath ?Acapulco
can you try making imageView.contentMode = UIViewContentModeScaleAspectFit;Suppressive
Answered here -#44772278Shevlo
H
13

Yes, this is an image size problem. Even I had a similar requirement and faced the same problem. In this case when you use,

action.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"remove"]];

Even if you set the imageView.contentMode to:

UIViewContentModeScaleAspectFit
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFill

If the size of the image you are using and and the size of the button on the cell do not match, the image will not stretch to fill the entire button, rather the image pattern will just repeat itself until the entire area of the button is utilised. This is because you are setting the 'backgroundColor' and not the actual 'backgroundImage'. 'backgroundColor' unlike 'backgroundImage' does not adhere to UIContentMode of the button.

Hence, what you will have to do is, create a image which is exactly equal to the size of the button. Doing this is not possible if your cell has a dynamic height (height determined at runtime according to your content).

Houle answered 26/5, 2016 at 6:8 Comment(1)
Hello , In my case i have managed the height but i have placed 3 buttons and now its stretching from width. The image is repeating in the Cell. Please help me in this case. Thanks.Surculose

© 2022 - 2024 — McMap. All rights reserved.