私はswiftでPDFを生成しようとしています。私は客観的なCから迅速に変換しようとしてきましたが、今は修正する方法がわからないといういくつかの誤りがあります。ここSwift 2.0でPDFを生成
コードである:
VARパス:[ANYOBJECT] =のNSSearchPathForDirectoriesInDomains(NSDocumentDirectory、NSUserDomainMask、真)
@IBAction func createPDFOnClick(sender: AnyObject!)
{
pageSize = CGSizeMake(850,1100)
let fileName: String = "makeME.pdf"
var path: [AnyObject] = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,true)
let documentDirectory: String = path[0] as! String
let pdfPathWithFileName: String = documentDirectory.stringByAppendingString(fileName)
self.createPDF(pdfPathWithFileName)
}
func createPDF(filePath: String){
UIGraphicsBeginPDFContextToFile(filePath,CGRectZero,nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0,0,850,1100),nil)
self.drawBackground()
self.drawText()
UIGraphicsEndPDFContext()
}
func drawBackground() {
let context: CGContextRef = UIGraphicsGetCurrentContext()!
let rect: CGRect = CGRectMake(0,0,pageSize!.width,pageSize!.height)
CGContextSetFillColorWithColor(context,UIColor.whiteColor().CGColor)
CGContextFillRect(context,rect)
}
func drawText() {
var context: CGContextRef = UIGraphicsGetCurrentContext()!
CGContextSetFillColorWithColor(context,UIColor.blackColor().CGColor)
var textRect: CGRect = CGRectMake(0,0,[[self myTextView]frame].size.with, self.myTextView.frame.size.height)
var myString: String = self.myTextView.text!
myString.drawInRect(textRect)
}
私のエラーは、次の行であります「未解決の識別子を使用する」エラーが表示される
のvar textRect:CGRect = CGRectMake(0,0、[[自己myTextView]フレーム] .size.with、self.myTextView.frame.size.height)ここで
i "は、セパレータを期待する" 取得しています
ありがとうございます。
** myString.drawInRect(textRect)**私はエラーを取得しています**予想引数の型に型「CGRect」の値を変換できません* *。 – mogren3000
期待される引数型は何ですか?そうでない場合は、その行を削除して再入力しますが、 'drawInRect'関数は自動補完を行い、プレースホルダのパラメータの内容を確認します。 –