最后,Swift 3有一个开箱即用的聊天气泡UI。
Chris Cates
s3c作为一个UIViewController,为您预先构建了一个聊天气泡视图。它与一个名为s3c_struct
的公开结构体直接工作。
在Podfile中
pod "s3c"
然后运行
pod install
import s3c
class myViewController: s3c {
override func viewDidLoad() {
super.viewDidLoad()
//Optional
let item = [
"from": "Chris Cates",
"message": "Woohoo! Easy Chat UIs",
"image": UIImage(named: "placeholder")
]
s3c_struct.messages.insert(item, at: 0)
//Required
initializeChat()
}
}
假设您有一组您想要传播到聊天气泡的消息。您只需通过addMessage()
函数进行代理
override func viewDidLoad() {
//What was in original...
}
func populateChat() {
let text: String = "My message"
let from: String = "Chris Cates"
let photo: UIImage = UIImage(named: "whatever_asset")
//Can just delegate messages via add message function
addMessage(text: text, from: from, photo: photo)
}
所有这些变量都是可编辑的,但请注意,未声明的变量将在上述示例中指定 的 initializeChat() 函数声明时重初始化
public struct s3c_struct {
static var offset: Int = 0
static var fontSize: Int = 14
static var photoSize: Int = 33
static var user1_name: String! = "Anonymous"
static var user1_photo: UIImage! = UIImage(named: "placeholder")
static var user2_name: String! = "Anonymous"
static var user2_photo: UIImage! = UIImage(named: "placeholder")
static var messagesContainer: UITableView!
static var messagesContainerDict: NSMutableDictionary!
static var messages: Array<Dictionary<String, Any>> = Array()
static var button: UIButton!
static var buttonDict: NSMutableDictionary!
static var input: UITextField!
static var inputDict: NSMutableDictionary!
}
在MIT许可证下发布 :)