IOS 구현 다이어그램 혼합

2207 단어

1. 로컬에서 txt 문서 가져오기


// txt 
        do {
            text = try NSString(contentsOfFile: NSBundle.mainBundle().URLForResource("haoshengyin", withExtension: "txt")!.path!, encoding: NSUTF8StringEncoding)
            text = (text as String).stringByAppendingString("
") }catch {} // scrollView , scrollView self.automaticallyAdjustsScrollViewInsets = false

2. textView 문서 작업


// MARK -- , , 
        // 
        let attributedTextString = NSMutableAttributedString(string: text as String)
        // , 1.35 
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineHeightMultiple = 1.35*y1
        // ,1. ,2. ,3 ,4. 
        attributedTextString.setAttributes([NSKernAttributeName:1.8*y1,NSParagraphStyleAttributeName:paragraphStyle], range: NSMakeRange(0, text.length))
        attributedTextString.setAttributes([NSFontAttributeName:UIFont.boldSystemFontOfSize(18.0*y1),NSForegroundColorAttributeName:UIColor.blackColor()], range: NSMakeRange(0, 18))

        // textView 
        let textView1 = UITextView(frame:CGRectMake(15*x, 44+20*y1 , self.view.frame.size.width - 30*x, self.view.frame.size.height-44-20*y1))
        textView1.font = UIFont(name: "FZZhunYuan-M02S", size: 17.0*y1)
        textView1.attributedText = attributedTextString
        textView1.showsVerticalScrollIndicator = false
        textView1.editable = false
        textView1.scrollEnabled = true
        self.scrollView.addSubview(textView1)

3. 그림을 첨부 파일로 설정하여 가변 텍스트에 넣는다


// MARK -- 
        let string = NSMutableAttributedString(attributedString: textView1.attributedText)
        // 
        let textAttachment = NSTextAttachment(data: nil, ofType: nil)
        // 
        textAttachment.image = UIImage(named: "hsy.png")
        // 
        textAttachment.bounds = CGRectMake(0, 0 , self.view.frame.size.width-30*x, 300*y1)
        // 
        string.insertAttributedString(NSAttributedString(attachment: textAttachment), atIndex: self.text.length)
        // textView 
        textView1.attributedText = string

좋은 웹페이지 즐겨찾기