UITableViewRowAction with image instead of title

。_饼干妹妹 提交于 2019-12-04 04:29:28

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!