Reputation: 41
I'm trying to make sth similar to bullet list in TextView but instead of bullets I have an image. The problem is that when I create the new line by normal "\n
" sign the space before the image in the line is editable.
And I want to make that image to be always first sign in line
So I'm asking about:
u can't pass text before a bullet
private var stringWithNewPointersInside = NSMutableAttributedString()
private var pointerAsTextValue = NSAttributedString()
private var image = UIImage()
private var imageView = UIImageView()
private let pointer = NSTextAttachment()
public func checkList(noteTextValue: NSAttributedString) -> NSMutableAttributedString {
stringWithNewPointersInside = NSMutableAttributedString(attributedString: noteTextValue)
stringWithNewPointersInside.append(NSAttributedString(string: "\n"))
pointer.image = createImage(name: EMPTY_TICK_IMAGE, newSize: CGSize(width: WIDTH, height: HEIGHT))
pointerAsTextValue = NSAttributedString(attachment: pointer)
stringWithNewPointersInside.append(pointerAsTextValue)
stringWithNewPointersInside.append(NSAttributedString(string: " "))
return stringWithNewPointersInside
}
private func createImage(name: String, newSize: CGSize) -> UIImage{
var newImage = UIImage(named: name)!
UIGraphicsBeginImageContext(newSize)
newImage.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
Upvotes: 3
Views: 242