Menu

Tree [66bbfb] master /
 History

HTTPS access


File Date Author Commit
 .gitignore 2017-06-23 Jonathan Sullivan Jonathan Sullivan [c6b6fe] Add .gitignore
 JPSLayoutManager.swift 2017-06-23 Jonathan Sullivan Jonathan Sullivan [b68466] Seperate files.
 JPSTextAttachment.swift 2017-06-23 Jonathan Sullivan Jonathan Sullivan [66bbfb] Rename JPSTextAttachmentDrawingView to JPSTextA...
 JPSTextStorage.swift 2017-06-23 Jonathan Sullivan Jonathan Sullivan [b68466] Seperate files.
 JPSTextView.swift 2017-06-23 Jonathan Sullivan Jonathan Sullivan [b68466] Seperate files.
 LICENSE 2017-06-23 Jonathan Sullivan Jonathan Sullivan [bf978b] Create LICENSE
 README.md 2017-06-23 Jonathan Sullivan Jonathan Sullivan [9a4fd4] Update README.md

Read Me

JPSTextKit

An implementation of NSTextAttachment and NSLayoutManager for displaying custom inline UIViews.

Example: Creating a Checkbox TextAttachment in a TextView

  1. Configure a JPSTextView.
let defaultAttributes = [NSFontAttributeName: <# UIFont #>,
                         NSForegroundColorAttributeName: <# UIColor #>]

self.textView = JPSTextView(frame: <# CGRect #>)
self.textView.setDefaultAttributes(defaultAttributes)
self.textView.font = defaultAttributes[NSFontAttributeName] as? UIFont
self.textView.textColor = defaultAttributes[NSForegroundColorAttributeName] as? UIColor
self.contentView.addSubview(self.textView)
  1. Configure and add a JPSTextAttachment.
guard let image = UIImage(named: <# Image Name #>) else { return }
let checkboxImage = image.withRenderingMode(.alwaysTemplate)
let checkboxButton = UIButton(type: .custom)
checkboxButton.tintColor = <# UIColor #>
checkboxButton.setBackgroundImage(checkboxImage, for: .normal)
checkboxButton.addTarget(self, action: <# Selector #>, for: .touchUpInside)
checkboxButton.frame = CGRect(origin: CGPoint.zero, size: checkboxImage.size)

let checkboxAttachment = JPSTextAttachment()
checkboxAttachment.bounds = checkboxButton.bounds
checkboxAttachment.contentView.addSubview(checkboxButton)

let checkboxString = NSAttributedString(attachment: checkboxAttachment)
self.textView.textStorage.replaceCharacters(in: <# Range #>, with: checkboxString)
  1. Update the UITextView.selectedRange.
let selectedRange = self.textView.selectedRange
self.textView.selectedRange = NSRange(location: selectedRange.location + 1, length: 0)
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.