简体   繁体   English

适用于iOS的条款和条件View Controller

[英]Terms and Conditions View Controller for iOS

I was trying to make a simple Terms and Conditions view controller for my app. 我试图为我的应用制作一个简单的“条款和条件”视图控制器。 I was figuring a ScrollView with a Text Field. 我在想一个带有文本字段的ScrollView。

What I am running into is displaying a really long formatted text string with multiple line feeds and quoted words and phrases. 我正在遇到的问题是显示一个格式很长的文本字符串,其中包含多个换行符以及带引号的单词和短语。

NSString @termsAndConditions = @"Terms and Conditions ("Terms") ...
    ...
    ..."

How have others handled this? 别人如何处理呢? Since terms can change, how would one program this to be easily updated? 由于术语可以更改,因此如何轻松地对此程序进行更新?

A code example would be really appreciated. 一个代码示例将不胜感激。

There is no one right way to ever do anything. 没有一种正确的方法来做任何事情。 What I have done in the past is to have the client or copywriter supply a word document. 我过去所做的就是让客户或文案撰写人提供Word文档。 A word document is great for some one maintaining the content because it is easy for a non programmer. 单词文档对某些维护内容的人非常有用,因为对于非程序员来说很容易。 It also allows someone to easily specify some simple formatting for their terms of service content. 它还允许某人轻松地为其服务条款指定一些简单的格式。 Ie. IE浏览器。 bullet list, headers, links etc. 项目符号列表,标题,链接等。

Then I would use an online doc2html converter to create an HTML file. 然后,我将使用在线doc2html转换器创建HTML文件。 (There are plenty of these online, a quick google can find one) Then I display the HTML file in a web view with in the terms of service or privacy policy view controller. (在线上有很多这样的内容,一个快速的google可以找到一个)然后,我在Web视图中显示HTML文件,其中包含服务条款或隐私权政策视图控制器。 If the app is using a specific font I just use a text editor to string replace the font declarations. 如果应用程序使用的是特定字体,则只需使用文本编辑器来字符串替换字体声明即可。 Any extra styling requirements can be specified in a separate css file. 可以在单独的CSS文件中指定任何其他样式要求。 For example, one that I just did required a specific colour for links to fit the theme of the app. 例如,我刚刚做了一个操作,要求链接使用特定的颜色以适合应用程序的主题。

When it needs updating I can usually just do the edits in HTML if their are a few or regenerate it from a new Doc file. 当需要更新时,我通常可以用HTML进行编辑(如果编辑很少),或者从新的Doc文件重新生成。

Here is some example code of the view controller: 这是视图控制器的一些示例代码:

class TermsViewController: UIViewController {

    @IBOutlet weak var termsWebView: UIWebView!

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        loadTermsHTML()
    }


    func loadTermsHTML() {

        //Load the HTML file from resources
        guard let path = NSBundle.mainBundle().
                          pathForResource("terms", ofType: "html") else {
            return
        }

        let url = NSURL(fileURLWithPath: path)

        if let data = NSData(contentsOfURL: url) {

            termsWebView.loadHTMLString(NSString(data: data, 
             encoding: NSUTF8StringEncoding) as! String, baseURL: nil)

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM