如何将UIView保持在1920x1080px的大小

时间:2019-01-02 12:30:05

标签: swift uiview uiimage uiimagepickercontroller image-resizing

我有一个UIView,其中textfield和图像将加载到UIImage中,我保存了UIView区域中包含的所有内容,但是保留了低分辨率,并且需要特定的尺寸。

uiview size on storyboard

@IBAction func shareButton(_ sender: AnyObject) {
    renderImageWithText()
}

// RENDER IMAGE WITH TEXT
func renderImageWithText() {
    let rect = cropView.bounds

    UIGraphicsBeginImageContext(CGSize(width: cropView.frame.size.width, height: cropView.frame.size.height))
    cropView.drawHierarchy(in: CGRect(x: 0.0, y: 0.0, width: cropView.frame.size.width, height: cropView.frame.size.height), afterScreenUpdates: true)

    imageToBeShared = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    openShareMenu()    
}


// OPEN SHARE
func openShareMenu() {

    let shareItems = [imageToBeShared!] as [Any]
    let actVC = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    actVC.excludedActivityTypes = [.print, .postToWeibo, .copyToPasteboard, .addToReadingList, .postToVimeo]
    if UIDevice.current.userInterfaceIdiom == .pad {
        // iPad
        let popOver = UIPopoverController(contentViewController: actVC)
        popOver.present(from: CGRect(x: self.view.frame.size.width/2, y: self.view.frame.size.height/2, width: 0, height: 0), in: self.view, permittedArrowDirections: .down, animated: true)
    } else {
        // iPhone
        present(actVC, animated: true, completion: nil)
    }
}

0 个答案:

没有答案