我正在開發一個應用程序,我有一個文本以及UIImage
在UITextView
裏面,我試圖垂直對齊文本以及圖像在水平方向左側,我怎麼能做到這一點?垂直和水平對齊的文本以及UIImage在UITextView內
let image = UIImage(named: "Downward Arrow - 01.png") //Step (10) This is where the image is defined.
let attachment = NSTextAttachment() // Step (10) inserting a NSTextAttachment in order to attach the image in a UITextView.
let scaledImage = image?.scaleImageToSize(img: image!, size: CGSize(width: 30, height: 30)) // this line of code is needed in order to resize the size of the image.
attachment.image = scaledImage // Step (10) setting the image to be attached to the scaled one that we just obtained out of the previous code.
//put your NSTextAttachment into and attributedString
let attString = NSAttributedString(attachment: attachment) // Step (10).
testTextView.textStorage.insert(attString, at: testTextView.selectedRange.location) // Step (10).
您是否使用'UITextField'或'UITextView'? – GIJOW
我正在使用UITextView –