3

I was trying to make a simple Terms and Conditions view controller for my app. I was figuring a ScrollView with a Text Field.

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
lr100
  • 648
  • 1
  • 9
  • 29

1 Answers1

5

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. 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. bullet list, headers, links etc.

Then I would use an online doc2html converter to create an HTML file. (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. 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. 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.

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)

        }
    }
}
Dave Thomas
  • 3,667
  • 2
  • 33
  • 41