【澳门葡京备用网址】富文本实现,达成富文本突显

简介:

简介:

更详细的剧情能够参照官方文书档案 《Text Programming Guide for
iOS》。

1. Text Kit基础  

        Text Kit最重大的成效 是为顺序提供文字排版和渲染的职能。通过Text
基特能够对文字进行仓库储存、布局,以更为精 的排版方式来展现文本内容。Text
Kit属于UIKit框架,个中包 了一些文字排版的相关类和协 。 

        在iOS 7以前未曾Text
Kit。文本控件,如:UILabel、UITextField和UITextView是依赖String
Drawing和WebKit构建的。在那之中String Drawing与Core
Graphics接通讯。由此在iOS
柒以前文本控件也能够实现两种体裁的文字排版,不过实际是经过WebKit落成的。WebKit是壹种浏览器内核才干,使用它实行理文件字渲染会 
  较多的内部存款和储蓄器,对利用的性情有一定的  。

     
在iOS7之后,UILabel、UITextfField和UITextView构建于TextKit之上,Text
Kit是基于Core Text构建的, 通过Core Text与Core Graphics进行交 。

澳门葡京备用网址 1

Core
Text主要用来对文件实行排版布局和字体处理,与其他UI组件比较,由于它直接与Quartz交互,因而排版效用高,渲染速度快。

Core
Text主要用来对文件实行排版布局和字体管理,与其余UI组件比较,由于它间接与Quartz交互,由此排版功能高,渲染速度快。

“Text
基特指的是UIKit框架中用于提供高素质排版服务的1部分类和商量,它让程序可以存款和储蓄,排版和展现文本音讯,并帮忙排版所急需的持有本性,包蕴字距调节、连写、换行和对齐等。”

壹.一 Text Kit中的大旨类  

我们在应用Text Kit时,会 及如下大旨类。

1.  `NSTextContainer。定 了文本能够排版的区 。 认情形下是矩形区
,假设是此外形状的区域,须要经过子类化NSTextContainer来创建。`

  1. `NSLayoutManager。该类负担对文字举行编
    排版管理,将积累在NSTextStorage中的数据调换为能够在视图控件中显得的文书内容,并把字编码映射到到对应的字形上,然后将字形排版到NSTextContainer定义的区域中。`

  2. `NSTextStorage。重要用来囤积文本的字 和连锁属性`

  3. `NSAttributedString。 持渲染区别风格的文书。`

  4. `NSMutableAttributedString。可变类
    的NSAttributedString,是NSAttributedString的子类`

NSLayoutManager对象从NSTextStorage对象中赢得文本内容,
举行排版,然后把排版之后的文本放到NSTextContainer对象钦赐的区 上。最终由三个文书控件从 NSTextContainer中抽出内容展现到显示器中。

澳门葡京备用网址 2

下图是Core Text的架构图:

下图是Core Text的架构图:

初始,若是大家想实现复杂的文件排版,举例在textView中展现不一致体制的文书,或然图片和文字混排,你或者就供给注重于UIWebView照旧深远钻研一下Core Text。在iOS6中,UILabelUITextFieldUITextView追加了一个NSAttributedString性格,能够稍微缓慢解决1部分排版难题,不过援救的力度还不够。现在Text
Kit完全改造了这种现状。

一.贰 凸印效果的完毕

间接上代码

//创建3个矩形区,那么些区是由此CGRectInset函数创制的,这么些函数能钦赐一在那之中

//心点,前面的八个参数着self.view.bounds区域向Nene进量。那样能够使得文字部分不会太接近视图的境界。

CGRecttextViewRect =CGRectInset(self.view.bounds,10.0,20.0);

//首要用来存款和储蓄文本的字和血脉相通属性

NSTextStorage* textStorage =
[[NSTextStoragealloc]initWithString:_textView.text];

//该类担当对文字举办编排版管理,将积累在NSTextStorage中的数据转换为能够在视图控件中展现的文书内容

NSLayoutManager* layoutManager = [[NSLayoutManageralloc]init];

[textStorageaddLayoutManager:layoutManager];

//定义了文件能够排版的区

_textContainer=
[[【澳门葡京备用网址】富文本实现,达成富文本突显。NSTextContaineralloc]initWithSize:textViewRect.size];

/**

*NSLayoutManager对象从NSTextStorage对象中获取文本内容,实行排版,

*接下来把排版之后的文书放到NSTextContainer对象钦命的区域上。

*终极由一个文件控件从NSTextContainer中抽取内容显示到显示屏中。

*/

[layoutManageraddTextContainer:_textContainer];

[_textViewremoveFromSuperview];

_textView= [[UITextViewalloc]initWithFrame:textViewRect

textContainer:_textContainer];

_textView.textColor= [UIColoryellowColor];

_textView.editable=NO;

[self.viewaddSubview:_textView];

//设置凸印效果

[textStoragebeginEditing];

NSDictionary*attrsDic
=@{NSTextEffectAttributeName:NSTextEffectLetterpressStyle};

NSMutableAttributedString*attrStr =
[[NSMutableAttributedStringalloc]

initWithString:_textView.text

attributes:attrsDic];

[textStoragesetAttributedString:attrStr];

[self markWord:@”you”inTextStorage:textStorage];

[self markWord:@”I”inTextStorage:textStorage];

[self markWord:@”言”inTextStorage:textStorage];

[textStorageend Editing];

标记制定文字

– (void) markWord:(NSString*)word
inTextStorage:(NSTextStorage*)textStorage{

NSRegularExpression*regex =
[NSRegularExpressionregularExpressionWithPattern:word

options:0

error:nil];

NSArray*matches = [regexmatchesInString:_textView.text

options:0

range:NSMakeRange(0,[_textView.textlength])];

for(NSTextCheckingResult*matchinmatches) {

NSRangematchRange = [matchrange];

[textStorageaddAttribute:NSForegroundColorAttributeName

value:[UIColorredColor]

range:matchRange];

}

效果图:

澳门葡京备用网址 3

富文本

澳门葡京备用网址 4

澳门葡京备用网址 5

澳门葡京备用网址 6

1.三 图像和文字混排

Text Kit通过环绕路线(exclusion
paths)将文字依据钦点的门路环绕在图纸等视图对象的方圆

// 在上面代码基础上,增添二个UIImageView

// 钦点NSTextContainer环绕路线完结图像和文字混排

//设置环绕路线,能够内定多少个

_textView.textContainer.exclusionPaths=@[[selftranslatedBezierPath]];

收获UIImageView的贝塞尔曲线

-(UIBezierPath*) translatedBezierPath{

//将imageView相对于View的坐标转换为相对于textView的坐标

CGRectimageRect = [self.textViewconvertRect:_imageView.frame

fromView:self.view];

UIBezierPath*newPath =
[UIBezierPathbezierPathWithRect:imageRect];

return newPath;

}

效果图

澳门葡京备用网址 7

图像和文字混排

富文本完毕:(GitHub传送门)

富文本落成:(GitHub传送门)

Text Kit是基于Core
Text营造的高效、先进的文书排版和渲染引擎,并且与UIKit很好的集纳。UITextViewUITextFieldUILabel都已经根据Text
Kit重新创设,所以它们都支持分页文本、文本包装、富文本编辑、交互式文本着色、文本折叠和自定义截取等风味。全数那么些UI控件未来都是同样的措施构建,在它们背后,多个NSTextStorage澳门葡京备用网址,对象保存着公文的重中之重音信,它本人是NSMutableAttributedString的子类,支持分批编辑。那就意味着你能够变动1个范围内的字符的体裁而不用一体化替换文本内容。

一.④ 动态字体

注册UIContentSizeCategoryDidChangeNotification公告,完成动态字体作用

[[NSNotificationCenterdefaultCenter]addObserver:self

selector:@selector(preferredContentSizeChanged:)

name:UIContentSizeCategoryDidChangeNotification

object:nil];

#pragma mark –监听字体变化

– (void)preferredContentSizeChanged:(NSNotification*)notification{

// do something

}

接下去大家经过3个例子来探视怎么样贯彻富文本浮现。我们按职分将作用拆分成几个类来实现,

接下去大家通过四个例子来探望怎样贯彻富文本彰显。大家按任务将功效拆分成多少个类来完结,

[self.textView.textStorage beginEditing];
[self markWord:@"Alice" inTextStorage:self.textView.textStorage];
[self.textView.textStorage endEditing];

图像和文字混排cpu、memory使用越来越高,怎么优化?

demo地址

一.一个来得的类,CTDisplayView,仅负担突显。

1.贰个显得的类,CTDisplayView,仅担当显示。

Text
storage管理者1多元的NSLayoutManager目的,当它的字符恐怕性质改换时会公告到协调所管理的layout
Manager对象以便它们作出相应的反射。在layout
manager上边是八个NSTextContainer目的,用于为layout
manager定义坐标系和部分几何特征。举例,若是您想UITextView中的文本环绕在一张图纸四周,你能够给text
container设定2个排除路线(exclusion path)。

import UIKit

class CTDisplayView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var data:CoreTextData?

    override func draw(_ rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()

        //翻转坐标系
        context?.textMatrix = CGAffineTransform.identity
        context?.translateBy(x: 0, y: self.bounds.size.height)
        context?.scaleBy(x: 1, y: -1)

        if data != nil {
            CTFrameDraw((self.data?.ctFrame)!, context!)
        }
    }

}
import UIKit

class CTDisplayView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var data:CoreTextData?

    override func draw(_ rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()

        //翻转坐标系
        context?.textMatrix = CGAffineTransform.identity
        context?.translateBy(x: 0, y: self.bounds.size.height)
        context?.scaleBy(x: 1, y: -1)

        if data != nil {
            CTFrameDraw((self.data?.ctFrame)!, context!)
        }
    }

}
UIBezierPath *exclusion = ButterflyBezierPath;
self.textView.textContainer.exclusionPaths = @[exclusion];

 

 

澳门葡京备用网址 8

二.三个布置类,CTFrameParserConfig,肩负安顿部分暗中认可的参数。

二.一个陈设类,CTFrameParserConfig,负担安插部分暗中同意的参数。

Text container能够管理击中测试(hit
tests),所以能够固定到点击的字符在文书中的位置。其它它还提供一些代理方法让开采者能够和谐定义链接点击后的处管事人件。

import UIKit

class CTFrameParserConfig: NSObject {
    var width:CGFloat = 200.0
    var fontName: NSString = "PingFangSC-Regular"
    var fontSize: CGFloat = 17.0
    var lineSpace: CGFloat = 0.0
    var textColor = ColorRGBA(r: 0, g: 0, b: 0, a: 1)
}
import UIKit

class CTFrameParserConfig: NSObject {
    var width:CGFloat = 200.0
    var fontName: NSString = "PingFangSC-Regular"
    var fontSize: CGFloat = 17.0
    var lineSpace: CGFloat = 0.0
    var textColor = ColorRGBA(r: 0, g: 0, b: 0, a: 1)
}

澳门葡京备用网址 9

 

 

由此依照Text
Kit重新营造UILabelUITextFieldUITextView,苹果给开采者更加大的油滑和力量来设计富文本视图,同时简化了那些控件的施用,因为它们是以同壹的诀窍设计的,全体这一个利润都是站在有影响的人(Core
Text)的肩上。平常越来越强有力的功力和灵活性也就表示必要越来越多的安装和保管,不过,假如您只是想体现一段轻易的文本,你仍可以像此前一样使用。

三.1个排版类,CTFrameParser,负担兑现内容的排版。

三.1个排版类,CTFrameParser,担当兑现内容的排版。

self.textLabel.text = @"Hello Text Kit";
class CTFrameParser: NSObject {

    // MARK: ------处理模板文件并返回数据源------
    class func parserTemplateFlie(_ path: NSString, config: CTFrameParserConfig) -> CoreTextData {
        let content = self.loadTemplateFile(path, config: config)
        return self.parserAttributedContent(content, config: config)
    }

    // MARK: ------加载模板文件------
    class func loadTemplateFile(_ path: NSString, config: CTFrameParserConfig) -> NSAttributedString {
        let data = NSData(contentsOfFile: path as String)
        let result = NSMutableAttributedString()
        if (data != nil) {
            let array:NSArray = try! JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
            if array.isKind(of: NSArray.self) {
                for dic in array {
                    if let dict = dic as? NSDictionary {
                        let type = dict["type"]
                        if ((type as! NSString).isEqual(to:"txt")) {
                            let attributedStr = self.parserAttributedContentConvert(dict, config: config)
                            result.append(attributedStr)
                        }
                    }
                }
            }
        }
        return result
    }

    // MARK: ------设置文字模板描述------
    class func parserAttributedContentConvert(_ dict: NSDictionary, config: CTFrameParserConfig) -> NSAttributedString {
        let attributes:NSMutableDictionary = self.attributes(config) as! NSMutableDictionary

        //colorConvert
        let colorStr = (dict["color"]) as? String
        if (colorStr != nil && colorStr != "default") {
            let hexValue = Int(strtoul(colorStr, nil, 16))
            let color = ColorHEX(hexValue: hexValue)
            attributes.setObject(color, forKey: kCTForegroundColorAttributeName as! NSCopying)
        }

        //fontConvert
        var fontName = dict["fontName"] as? String
        var fontSize = dict["fontSize"] as? CGFloat
        if (fontName == nil || fontName == "default") {
           fontName = config.fontName as String
        }
        if (fontSize == nil || fontSize! <= 0) {
           fontSize = config.fontSize
        }
        let font = CTFontCreateWithName(fontName as CFString?, fontSize!, nil)
        attributes.setObject(font, forKey: kCTFontAttributeName as! NSCopying)

        let content = dict["content"] as! NSString

        return NSAttributedString(string: content as String, attributes: attributes.copy() as? [String : Any])
    }

    // MARK: ------设置初始化描述------
    class func attributes(_ config: CTFrameParserConfig) -> NSDictionary {
        //设置字体
        let fontName = config.fontName
        let fontSize = config.fontSize
        let fontRef = CTFontCreateWithName(fontName as CFString?, fontSize, nil)

        //设置行间距
        var lineSpace = config.lineSpace
        let settings: [CTParagraphStyleSetting] = [CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.lineSpacingAdjustment, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace), CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.maximumLineSpacing, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace), CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.minimumLineSpacing, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace)]
        let theParagaraphRef = CTParagraphStyleCreate(settings, 3)

        //设置字体颜色
        let textColor = config.textColor

        let dict = NSMutableDictionary()
        dict.setObject(fontRef, forKey: kCTFontAttributeName as! NSCopying)
        dict.setObject(theParagaraphRef, forKey: kCTParagraphStyleAttributeName as! NSCopying)
        dict.setObject(textColor.cgColor, forKey: kCTForegroundColorAttributeName as! NSCopying)

        return dict
    }

    // MARK: ------获取数据源------
    class func parserAttributedContent(_ content: NSAttributedString, config: CTFrameParserConfig) -> CoreTextData {
        let frameSetter = CTFramesetterCreateWithAttributedString(content)
        let restrictSize = CGSize(width: config.width, height: CGFloat(MAXFLOAT))
        let coretextSize = CTFramesetterSuggestFrameSizeWithConstraints(frameSetter, CFRangeMake(0, 0), nil, restrictSize, nil)
        let textHeight = coretextSize.height

        let frame = self.createFrame(frameSetter, config: config, height: textHeight)

        let data = CoreTextData(ctFrame: frame, height: textHeight)

        return data
    }

    // MARK: ------创建frame------
    class func createFrame(_ frameSetter: CTFramesetter, config: CTFrameParserConfig, height: CGFloat) -> CTFrame {
        let path = CGMutablePath()
        path.addRect(CGRect(x: 0, y: 0, width: config.width, height: height))

        let frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, nil)

        return frame
    }

}
class CTFrameParser: NSObject {

    // MARK: ------处理模板文件并返回数据源------
    class func parserTemplateFlie(_ path: NSString, config: CTFrameParserConfig) -> CoreTextData {
        let content = self.loadTemplateFile(path, config: config)
        return self.parserAttributedContent(content, config: config)
    }

    // MARK: ------加载模板文件------
    class func loadTemplateFile(_ path: NSString, config: CTFrameParserConfig) -> NSAttributedString {
        let data = NSData(contentsOfFile: path as String)
        let result = NSMutableAttributedString()
        if (data != nil) {
            let array:NSArray = try! JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
            if array.isKind(of: NSArray.self) {
                for dic in array {
                    if let dict = dic as? NSDictionary {
                        let type = dict["type"]
                        if ((type as! NSString).isEqual(to:"txt")) {
                            let attributedStr = self.parserAttributedContentConvert(dict, config: config)
                            result.append(attributedStr)
                        }
                    }
                }
            }
        }
        return result
    }

    // MARK: ------设置文字模板描述------
    class func parserAttributedContentConvert(_ dict: NSDictionary, config: CTFrameParserConfig) -> NSAttributedString {
        let attributes:NSMutableDictionary = self.attributes(config) as! NSMutableDictionary

        //colorConvert
        let colorStr = (dict["color"]) as? String
        if (colorStr != nil && colorStr != "default") {
            let hexValue = Int(strtoul(colorStr, nil, 16))
            let color = ColorHEX(hexValue: hexValue)
            attributes.setObject(color, forKey: kCTForegroundColorAttributeName as! NSCopying)
        }

        //fontConvert
        var fontName = dict["fontName"] as? String
        var fontSize = dict["fontSize"] as? CGFloat
        if (fontName == nil || fontName == "default") {
           fontName = config.fontName as String
        }
        if (fontSize == nil || fontSize! <= 0) {
           fontSize = config.fontSize
        }
        let font = CTFontCreateWithName(fontName as CFString?, fontSize!, nil)
        attributes.setObject(font, forKey: kCTFontAttributeName as! NSCopying)

        let content = dict["content"] as! NSString

        return NSAttributedString(string: content as String, attributes: attributes.copy() as? [String : Any])
    }

    // MARK: ------设置初始化描述------
    class func attributes(_ config: CTFrameParserConfig) -> NSDictionary {
        //设置字体
        let fontName = config.fontName
        let fontSize = config.fontSize
        let fontRef = CTFontCreateWithName(fontName as CFString?, fontSize, nil)

        //设置行间距
        var lineSpace = config.lineSpace
        let settings: [CTParagraphStyleSetting] = [CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.lineSpacingAdjustment, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace), CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.maximumLineSpacing, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace), CTParagraphStyleSetting(spec: CTParagraphStyleSpecifier.minimumLineSpacing, valueSize: MemoryLayout<CGFloat>.size, value: &lineSpace)]
        let theParagaraphRef = CTParagraphStyleCreate(settings, 3)

        //设置字体颜色
        let textColor = config.textColor

        let dict = NSMutableDictionary()
        dict.setObject(fontRef, forKey: kCTFontAttributeName as! NSCopying)
        dict.setObject(theParagaraphRef, forKey: kCTParagraphStyleAttributeName as! NSCopying)
        dict.setObject(textColor.cgColor, forKey: kCTForegroundColorAttributeName as! NSCopying)

        return dict
    }

    // MARK: ------获取数据源------
    class func parserAttributedContent(_ content: NSAttributedString, config: CTFrameParserConfig) -> CoreTextData {
        let frameSetter = CTFramesetterCreateWithAttributedString(content)
        let restrictSize = CGSize(width: config.width, height: CGFloat(MAXFLOAT))
        let coretextSize = CTFramesetterSuggestFrameSizeWithConstraints(frameSetter, CFRangeMake(0, 0), nil, restrictSize, nil)
        let textHeight = coretextSize.height

        let frame = self.createFrame(frameSetter, config: config, height: textHeight)

        let data = CoreTextData(ctFrame: frame, height: textHeight)

        return data
    }

    // MARK: ------创建frame------
    class func createFrame(_ frameSetter: CTFramesetter, config: CTFrameParserConfig, height: CGFloat) -> CTFrame {
        let path = CGMutablePath()
        path.addRect(CGRect(x: 0, y: 0, width: config.width, height: height))

        let frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, nil)

        return frame
    }

}

正文翻译自《iOS 7: Text
Kit》

 

 

Posted by TracyYih – Oct 17 2013
如需转发,请申明: 本文来自 Esoft Mobile

肆.3个数据源,CoreTextData,担负提供呈现类的所需数据。

四.多少个数据源,CoreTextData,肩负提供呈现类的所需数据。

class CoreTextData: NSObject {
    var ctFrame: CTFrame?
    var height:CGFloat = 0

    init(ctFrame: CTFrame, height: CGFloat) {
        self.ctFrame = ctFrame
        self.height = height
    }
}
class CoreTextData: NSObject {
    var ctFrame: CTFrame?
    var height:CGFloat = 0

    init(ctFrame: CTFrame, height: CGFloat) {
        self.ctFrame = ctFrame
        self.height = height
    }
}

 

 

除此以外,大家要求经过3个模板文件来自定义要求体现的文本的音讯,参考如下:

此外,大家须求经过二个模板文件来自定义须求出示的文书的新闻,参考如下:

 [
  {
  "type": "txt",
  "content": "This is a ",
  "fontName": "default",
  "fontSize": 0,
  "color": "default"
  },
  {
  "type": "txt",
  "content": "simple attributeString ",
  "fontName": "Snell Roundhand Bold",
  "fontSize": 26,
  "color": "0xe7292e"
  },
  {
  "type": "txt",
  "content": "demo, ",
  "fontName": "PingFangSC-Light",
  "fontSize": 18,
  "color": "0xf9f9f9"
  },
  {
  "type": "txt",
  "content": "you can use it ",
  "fontName": "PingFangSC-Bold",
  "fontSize": 13,
  "color": "0x85d64d"
  },
  {
  "type": "txt",
  "content": "by adding a json template.",
  "fontName": "Papyrus",
  "fontSize": 20,
  "color": "0x333333"
  }
  ]
 [
  {
  "type": "txt",
  "content": "This is a ",
  "fontName": "default",
  "fontSize": 0,
  "color": "default"
  },
  {
  "type": "txt",
  "content": "simple attributeString ",
  "fontName": "Snell Roundhand Bold",
  "fontSize": 26,
  "color": "0xe7292e"
  },
  {
  "type": "txt",
  "content": "demo, ",
  "fontName": "PingFangSC-Light",
  "fontSize": 18,
  "color": "0xf9f9f9"
  },
  {
  "type": "txt",
  "content": "you can use it ",
  "fontName": "PingFangSC-Bold",
  "fontSize": 13,
  "color": "0x85d64d"
  },
  {
  "type": "txt",
  "content": "by adding a json template.",
  "fontName": "Papyrus",
  "fontSize": 20,
  "color": "0x333333"
  }
  ]

接下来我们去调整器里面,把displayView增多进来,完结要求的布局,

下一场大家去调整器里面,把displayView增加进来,完结要求的安顿,

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let ctView = CTDisplayView()
        view.addSubview(ctView)

        ctView.backgroundColor = UIColor.gray
        ctView.setX(view.x())
        ctView.setY(view.y()+64)
        ctView.setWidth(width: view.width())

        let config:CTFrameParserConfig = CTFrameParserConfig()
        config.width = ctView.width()
        config.lineSpace = 10

        let path = Bundle.main.path(forResource: "template", ofType: "json")
        let data = CTFrameParser.parserTemplateFlie(path! as NSString , config: config)
        ctView.data = data
        ctView.setHeight(height: data.height)

    }
override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let ctView = CTDisplayView()
        view.addSubview(ctView)

        ctView.backgroundColor = UIColor.gray
        ctView.setX(view.x())
        ctView.setY(view.y()+64)
        ctView.setWidth(width: view.width())

        let config:CTFrameParserConfig = CTFrameParserConfig()
        config.width = ctView.width()
        config.lineSpace = 10

        let path = Bundle.main.path(forResource: "template", ofType: "json")
        let data = CTFrameParser.parserTemplateFlie(path! as NSString , config: config)
        ctView.data = data
        ctView.setHeight(height: data.height)

    }

最后的贯彻效益如下:

聊起底的兑现效益如下:

澳门葡京备用网址 10

澳门葡京备用网址 11

 

 

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website