I write how to print and share image with other applications, for example, Twitter and Facebook, on iOS this time.
iOSの場合は、iOSのApp Extensionsと連携することによって実現します。(画像はPocket Noteでの実施例です。)
In case of iOS, you can cooperate with iOS's App Extensions.(Photographs below are examples of Pocket Note)
環境(Environment):Xcode 8.、Swift 3
早速コードです。UIActivityViewControllerを使用して、App Extensionsに画像を渡します。
This is sample code. Use UIActivityController and you can give an image App Extensions.
let _buttonPrint:UIButton = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
_buttonPrint.frame = CGRect(x: 10,y: 10,width: 40,height: 40)
_buttonPrint.addTarget(self, action: #selector(MainViewController.TouchUpButtonPrint), for: .touchUpInside)
self.view.addSubview(_buttonPrint)
}
func TouchUpButtonPrint(){
// 印刷する画像を取得(Get image for printing)
var printImage:UIImage! = GetPrintImage()
let activityViewController = UIActivityViewController(activityItems:[printImage],applicationActivities:nil)
activityViewController.modalPresentationStyle = UIModalPresentationStyle.popover
activityViewController.preferredContentSize = CGSize(width: 500,height: 500)
let popoverController = activityViewController.popoverPresentationController
popoverController?.delegate = self
popoverController?.permittedArrowDirections = UIPopoverArrowDirection.up
popoverController?.sourceView = _buttonPrint
popoverController?.sourceRect = _buttonPrint.bounds
self.present(activityViewController, animated: true, completion: nil)
printImage = nil
}
[関連記事(Articles)]
[Android]How to print and share image
にほんブログ村
クリエイティブライフ ブログランキングへ
0 件のコメント:
コメントを投稿