我正在尝试使某事类似于 TextView 中的项目符号列表,但我有一个图像而不是项目符号。问题是当我通过正常的“ \n
”创建新行时,在该行中的图像可编辑之前的空格。而且我想让该图像始终首先登录所以我在问:
- 项目符号点
- 而不是子弹图像
你不能在子弹前传递文字
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 }