JPSTextKit Code
Status: Alpha
Brought to you by:
live-to-think
File | Date | Author | Commit |
---|---|---|---|
.gitignore | 2017-06-23 |
![]() |
[c6b6fe] Add .gitignore |
JPSLayoutManager.swift | 2017-06-23 |
![]() |
[b68466] Seperate files. |
JPSTextAttachment.swift | 2017-06-23 |
![]() |
[66bbfb] Rename JPSTextAttachmentDrawingView to JPSTextA... |
JPSTextStorage.swift | 2017-06-23 |
![]() |
[b68466] Seperate files. |
JPSTextView.swift | 2017-06-23 |
![]() |
[b68466] Seperate files. |
LICENSE | 2017-06-23 |
![]() |
[bf978b] Create LICENSE |
README.md | 2017-06-23 |
![]() |
[9a4fd4] Update README.md |
An implementation of NSTextAttachment and NSLayoutManager for displaying custom inline UIViews.
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)
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)
let selectedRange = self.textView.selectedRange
self.textView.selectedRange = NSRange(location: selectedRange.location + 1, length: 0)