swift 用UITextView加载本地.txt文件

let path = Bundle.main.url(forResource: "Privacyagreement", withExtension: "txt")
let data = try! Data(contentsOf: path!)
let content = String(data: data, encoding: .utf8)
let textView = UITextView.init()
textView.frame = CGRect.init(x: 0, y: getNavgationBarHeight(), width: kScreenWidth, height: kScreenHeight-getNavgationBarHeight())
textView.text = content
self.view.addSubview(textView)
注意


image.png

这个地方一定要有没有的话需要手动添加下 不然path获取不到

你可能感兴趣的:(swift 用UITextView加载本地.txt文件)