Для этого вы должны использовать scrollViewDidScroll
метод делегата.Вы можете попробовать следующее:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// Table View Scroll Image
let viewContentOffset = textview.contentOffset
let viewContentSize = textview.contentSize
let viewBounds = textview.bounds.size
// Use Alpha value to manipulation
let bottomOffset = scrollView.contentSize.height - scrollView.bounds.size.height
let alpha = (scrollView.contentOffset.y / bottomOffset) * 2
}
Добавить изображение в TextView с помощью NSAttributtedString:
textView.text = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
let image = UIImage(named: "sampleImage.png");
let attachment = NSTextAttachment()
attachment.image = image
let attString = NSAttributedString(attachment: attachment)
textView.textStorage.insert(attString, at: textView.text.count/2)