将排列的图像传递到iMessage

时间:2018-07-20 17:33:37

标签: ios swift msmessage

我无法将图像从阵列发送到iMessenger。代码在下面。

@IBOutlet weak var pickerView: UIPickerView!
var imageNameArray = [String]()

override func viewDidLoad() {
    super.viewDidLoad()
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
    return 150
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let imageName: String = imageNameArray[row]
    let imageView = UIImageView (image:UIImage(named: imageName))
    imageView.frame = CGRect(x: 10, y: 10, width: 200, height: 150)

    return imageView
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return imageNameArray.count
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    //Karl: need to add if else statement for starting position of pickerView

    sendLabel.text = imageNameArray[row]
}

@IBAction func sendButton(_ sender: Any) {
    pressedSend()
}

func pressedSend(){
    let layout = MSMessageTemplateLayout()

    layout.image = UIImage(named: "image1")

    let message = MSMessage()
    message.layout = layout
    message.url = URL(string: "emptyURL")

    activeConversation?.insert(message, completionHandler: nil)
}

0 个答案:

没有答案