不在UItableView Swift 4的滑动操作中显示标题 [英] Not displaying the title in Swipe actions for UItableView Swift 4

查看:217
本文介绍了不在UItableView Swift 4的滑动操作中显示标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在UItableViewCell的前端设置了添加到购物车的操作。我设置了背景颜色,图像和标题。下面是我的代码。

I have set an action for "add to cart" at leading side of the UItableViewCell. I have set background colour, its image and title. below's my code.

 @available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let addToCart = UIContextualAction(style: .normal, title: "Add to Cart") { (action, view, nil) in
        print("Added to cart")

    }
    addToCart.title = "Add to Cart"
    addToCart.backgroundColor = #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)
    addToCart.image = UIImage(named: "cart")

    return UISwipeActionsConfiguration(actions: [addToCart])
}

之前的尝试:我没有使用 addToCart.title =添加到购物车定义标题但是,在没有获得之后它,我已经设定了。

previous attempts : I have not defined title using addToCart.title = "Add to Cart" but, after not getting it, I have set that.

我添加的图片尺寸为25 * 25,背景清晰,格式为.png。

The image I have added is of 25*25 of size, has clear background and is of .png format.

推荐答案


UIContextualAction su pports text image 。通过使用setImage:属性设置图像,基本上在创建对象时删除标题。如果您同时需要文字和图片,则需要创建带嵌入文字的图片

UIContextualAction supports either text or image. By setting the image with setImage: property, basically remove the title when creating the object. If you want both text and image, you need to create images with embedded text.

其中的错误在 UIContextualAction 中。它不会同时显示图像和标题,除非表格查看单元格高度为91磅。了解更多信息 forums.apple

its the bug in UIContextualAction. It does not show both image and title at the same time unless the table view cell height is 91 points. for more info you get forums.apple

这篇关于不在UItableView Swift 4的滑动操作中显示标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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