相关疑难解决方法(0)

如何拍摄UIView的屏幕截图?

我想知道我的iPhone应用程序如何利用特定的屏幕截图UIView作为UIImage.

我试过这段代码,但我得到的只是一张空白图片.

UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

myUIView尺寸为320x480,并且有一些子视图.这样做的正确方法是什么?

screenshot objective-c uiview ios

131
推荐指数
9
解决办法
10万
查看次数

将pdf的NSData转换为图像文件的NSData

嗨,我正在尝试将pdf文件另存为jpg文件。我有许多要查询的网址,这些网址链接都是1页pdf文件。

var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
let urlRequest = NSURLRequest(URL: NSURL(string: downloadUrl[index])!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in

  var savePath = path.stringByAppendingPathComponent(file_name + ".jpg")

  if let httpResponse = response as? NSHTTPURLResponse {
    if let contentType = httpResponse.allHeaderFields["Content-Type"] as? NSString {
      let fileType = contentType.componentsSeparatedByString("/").last! as! String
      if fileType == "pdf" {

        // convert to jpg before saving!

        NSFileManager.defaultManager().createFileAtPath(savePath, contents: convertedData, attributes: nil)
      } else {
        NSFileManager.defaultManager().createFileAtPath(savePath, contents: data, attributes: nil)
      }

      self.tableView.reloadData()
    } …
Run Code Online (Sandbox Code Playgroud)

pdf nsdata ios swift

5
推荐指数
0
解决办法
2114
查看次数

标签 统计

ios ×2

nsdata ×1

objective-c ×1

pdf ×1

screenshot ×1

swift ×1

uiview ×1