EdenList for iOS 2.1.0

8th October 2019 | EdenList

Last month, EdenList 2.1.0 for iOS was released, featuring new printing capabilities, Dark Mode for iOS 13, and improved accessibility with Dynamic Type support.

Printing

After nearly a decade, I finally purchased a new printer, which has some nice features such as AirPrint and a duplexer. AirPrint in particular is a very welcome addition, especially with the proliferation of mobile devices over the past dozen years. This was key for me to finally take a look at adding printing support to the iOS version of EdenList.

I was initially surprised that printing wasn't already a feature supported by default on iOS, even if in some rudimentary form. It seemed like it should have been a relatively simple concept, but ended up being far more complicated than I had originally assumed. It seems like printing something as commonplace as a list would be a simple matter, but it is not. The frameworks make it relatively simple to print things like images, text, HTML, or a PDF, but if you want more customized printing, then you will have to handle it yourself.

After considering several options on how to best print a standard table view of data, I decided to go with constructing an HTML page from the data and printing the generated web page. The standard UITableView only displays a subset of the total data, so one cannot just take the visible portion of the screen and print it, since there might be a lot of unseen information. That is why I went the route of using an HTML template and used that to display what to print.

The following is a code snippet from EdenList which shows taking an HTML template and forming a web page with the list's data. In this example, the print functionality is part of the Share sheet, instead of an isolated function.

		
let fileTitle = self.title ?? ""
let fileURL = NSURL(fileURLWithPath: self.filePath)

var htmlContent = ""

// Retrieve the print_template.html file and put into a string
let templatePath = Bundle.main.path(forResource: "print_template", ofType: "html")

do {
	htmlContent = try String(contentsOfFile:templatePath!, encoding: String.Encoding.utf8)
	// Swap out the title with the name of the file to print
	htmlContent = htmlContent.replacingOccurrences(of: "__LIST_TITLE__", with: fileTitle)
	
	var itemsHTML = ""
	
	// Loop through the records and construct an HTML table for printing
	for item in self.records {
		let checkedOption: String = item.itemChecked ? "checked " : ""
		let itemTemplate = """
			<tr>
				<td><input type="checkbox" \(checkedOption)/></td>
				<td>
					<h4>\(item.itemTitle)</h4>
					<h5>\(item.itemNotes)</h4>
				</td>
			</tr>
		"""
		
		itemsHTML += itemTemplate
	}
	
	htmlContent = htmlContent.replacingOccurrences(of: "__LIST_ITEMS__", with: itemsHTML)
	
} catch _ as NSError {
	
}

let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = fileTitle
printInfo.orientation = .portrait
printInfo.duplex = .longEdge
		
let formatter = UIMarkupTextPrintFormatter(markupText: htmlContent)
formatter.perPageContentInsets = UIEdgeInsets(top: 36, left: 36, bottom: 36, right: 36)

let excludedTypes:[UIActivity.ActivityType] = [.postToFacebook, .postToTwitter, .postToVimeo, .postToWeibo, .postToFlickr, .addToReadingList, .assignToContact, .saveToCameraRoll]
let shareVC = UIActivityViewController(activityItems: [fileTitle, fileURL, printInfo, formatter], applicationActivities: nil)

shareVC.excludedActivityTypes = excludedTypes

Dark Mode

One of the landmark features in iOS 13 is the new Dark Mode appearance. For apps which stick with the stock UI components, adopting Dark Mode is fairly straightforward. There were a couple of places where I needed to check for iOS 13, but I did not need to add too many specific changes to get EdenList to look presentable in iOS 13. I could have also set up Dark Mode-specific icons, but felt that the current images work pretty well with both light and dark appearances.


if #available(iOS 13.0, *) {
	messageLabel.textColor = UIColor.systemGray
} else {
	// Fallback on earlier versions
	messageLabel.textColor = UIColor.darkGray
}

However, if your app isn't set up to support Dark Mode at this time, especially if you have a more distinct or customized design, then you will want to ensure that you are using specified colors for your various elements, and not using Default colors.

Dynamic Type

I have been learning a lot about WCAG and accessibility standards lately, which led me to properly implement Dynamic Type throughout the app. To better support a range of text sizes, EdenList now better supports Dynamic Type. This is reminiscent of the various styles (paragraph, header, caption, etc.) that a word processor uses, so it uses predefined terms instead of explicit font sizes. By avoiding explicit font sizes, it allows iOS to resize the text dependent upon the user's settings.

To alter the size of text in iOS, go to Settings > Display & Brightness > Text Size and adjust the slider.