在textview中的每个新行中将图像作为项目符号

时间:2018-02-20 16:11:41

标签: swift textview nstextattachment bulletedlist

我试图使用类似于TextView中的项目符号列表而不是子弹我有一个图像。问题在于,当我按正常情况创建新行时,\n"在行中的图像可编辑之前签署空格。 而且我想让这个图像始终首先排成一行 所以我要问:

  1. 子弹点
  2. 而非子弹图像
  3. 你不能在子弹之前传递文字

    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
    }
    

0 个答案:

没有答案