UITableViewRowAction与图像而不是标题 [英] UITableViewRowAction with image instead of title

查看:151
本文介绍了UITableViewRowAction与图像而不是标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像邮件应用一样制作单元格滑动操作。

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

我将 UIImage 设置为 backgroundColor

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

但我在背景上并排重复我的图片。喜欢这个。
在此输入图片说明

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

图像尺寸有问题吗?
可以告诉我如何解决它或其他方法吗?

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

推荐答案

是的,这是一个图像大小问题。
即使我有类似的要求并遇到同样的问题。在这种情况下,当你使用时,

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"]];

即使你将imageView.contentMode设置为:

Even if you set the imageView.contentMode to:

UIViewContentModeScaleAspectFit
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFill

如果您正在使用的图像尺寸与单元格上按钮的大小不匹配,则图像将不会拉伸以填充整个按钮,而是图像图案将重复自身,直到使用按钮的整个区域。
这是因为你设置'backgroundColor'而不是实际的'backgroundImage'。与'backgroundImage'不同的'backgroundColor'不符合按钮的UIContentMode。

因此,您需要做的是,创建一个图像,完全等于按钮的大小。如果您的单元格具有动态高度(根据您的内容在运行时确定高度),则无法执行此操作。

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

这篇关于UITableViewRowAction与图像而不是标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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