Ios 带有上角、边框和阴影的聊天项目视图

Ios 带有上角、边框和阴影的聊天项目视图,ios,objective-c,swift,uitableview,Ios,Objective C,Swift,Uitableview,我正在尝试创建自定义单元格,看起来像聊天项目。 挑战是:将三角形添加到上角,并制作聊天项目的公共边框和阴影 所有“云”的宽度都相同 实现这一目标的最佳方式是什么 我有个主意: 创建UIView的子类Triangle,以绘制“cloud”的“tail”: 用法: let leftTailView: LeftTriangleView = { let tail = LeftTriangleView() tail.backgroundColor = .white

我正在尝试创建自定义单元格,看起来像聊天项目。 挑战是:将三角形添加到上角,并制作聊天项目的公共边框和阴影

所有“云”的宽度都相同

实现这一目标的最佳方式是什么

我有个主意:

创建UIView的子类Triangle,以绘制“cloud”的“tail”:

用法:

let leftTailView: LeftTriangleView = {
        let tail = LeftTriangleView()
        tail.backgroundColor = .white
        tail.isHidden = true

        return tail
    }()

let rightTailView: RightTriangleView = {
        let tail = RightTriangleView()
        tail.backgroundColor = .white
        tail.isHidden = true

        return tail
    }()

let cloudView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.95, alpha: 1)
        view.layer.cornerRadius = 5
        view.layer.masksToBounds = true

        return view
    }()



addSubview(cloudView)
addSubview(leftTailView)
addSubview(rightTailView)



leftTailView.anchor(topAnchor, left: nil, bottom: nil, right: bubbleView.leftAnchor, topConstant: 5, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 9, heightConstant: 6)

rightTailView.anchor(topAnchor, left: bubbleView.rightAnchor, bottom: nil, right: nil, topConstant: 5, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 9, heightConstant: 6)



If send message: 

rightTailView.isHidden = false


If received message: 

leftTailView.isHidden = false

检查此项谢谢,此ViewController创建类似单元格的iMessages,但我的单元格在左侧的tableview显示发送者和接收者消息中稍微复杂一些?不,这是奇数和偶数单元格的外观。我建议您可以使用图像制作1px,然后您可以设置imageview和Sitch。
let leftTailView: LeftTriangleView = {
        let tail = LeftTriangleView()
        tail.backgroundColor = .white
        tail.isHidden = true

        return tail
    }()

let rightTailView: RightTriangleView = {
        let tail = RightTriangleView()
        tail.backgroundColor = .white
        tail.isHidden = true

        return tail
    }()

let cloudView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.95, alpha: 1)
        view.layer.cornerRadius = 5
        view.layer.masksToBounds = true

        return view
    }()



addSubview(cloudView)
addSubview(leftTailView)
addSubview(rightTailView)



leftTailView.anchor(topAnchor, left: nil, bottom: nil, right: bubbleView.leftAnchor, topConstant: 5, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 9, heightConstant: 6)

rightTailView.anchor(topAnchor, left: bubbleView.rightAnchor, bottom: nil, right: nil, topConstant: 5, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 9, heightConstant: 6)



If send message: 

rightTailView.isHidden = false


If received message: 

leftTailView.isHidden = false