
demo2.png

demo1.png
場景需求,如圖,長按cell彈出展示的View有的需要6個item,有的需要4個item
UIRectCorner定義
public struct UIRectCorner : OptionSet {
public init(rawValue: UInt)
public static var topLeft: UIRectCorner { get }
public static var topRight: UIRectCorner { get }
public static var bottomLeft: UIRectCorner { get }
public static var bottomRight: UIRectCorner { get }
public static var allCorners: UIRectCorner { get }
}
參考UIRectCorner,自定義類似實現(xiàn)
// 靜態(tài)屬性集合
struct MenuItemType : OptionSet {
public var rawValue = 0 // 因為RawRepresentable的要求
public static var copys = MenuItemType(rawValue : 1 << 0)
public static var transmit = MenuItemType(rawValue : 1 << 1)
public static var collect = MenuItemType(rawValue : 1 << 2)
public static var delete = MenuItemType(rawValue : 1 << 3)
public static var revoke = MenuItemType(rawValue : 1 << 4)
public static var download = MenuItemType(rawValue : 1 << 5)
public static var allCase: MenuItemType {
return [.copys, .transmit, .collect, .delete, .revoke, .download]
}
}
用法示例
if message?.msgDirection == .incoming {
customMenu.itemType = [.copys,.transmit,.collect,.delete]
}else{
// customMenu.itemType = [.copys,.transmit,.collect,.revoke,.delete]
customMenu.itemType = .allCase
}
==========================
if itemType == .allCase {
itemCount = 6
containerView.addArrangedSubview(copyingButton)
containerView.addArrangedSubview(transmitButton)
.
}else if itemType.contains([.copys,.transmit,.collect,.delete,.revoke]){
itemCount = 5
containerView.addArrangedSubview(copyingButton)
....
}else {
...
}