我正在尝试使用UITextField
在NSTextAttachment
中显示图像,但我想在图像和文本之间留出一些水平空间。但是,将NSKernAttributeName
属性添加到属性字符串时,如下所示,它会将附件的高度重置为与周围文本相同的高度。
var str = NSMutableAttributedString(attributedString: NSAttributedString(attachment: imageAttachment))
str.addAttribute(NSKernAttributeName, value: 10, range: NSRange(location: 0,length: 1))
还有另一种方法可以在图像和文本之间添加水平空间吗?
答案 0 :(得分:-1)
最直接的方法是在字符串开始设置一些空格:
func newPositionPipe() {
let pipePosition1 = CGPoint(x: 63, y: 1275)
let pipePosition2 = CGPoint(x: 188, y: 1275)
let pipePosition3 = CGPoint(x: 315, y: 1275)
let pipePosition4 = CGPoint(x: 443, y: 1275)
let pipePosition5 = CGPoint(x: 565, y: 1275)
let pipePosition6 = CGPoint(x: 687, y: 1275)
var randomNumberBetween0And6 = Int(arc4random_uniform(6))
let pipePositions = [pipePosition1, pipePosition2, pipePosition3, pipePosition4, pipePosition5, pipePosition6]
greenPipe.position = pipePositions[randomNumberBetween0And6]
redPipe.position = pipePositions[randomNumberBetween0And6]
greenPipe.position = pipePositions[randomNumberBetween0And6]
yellowPipe.position = pipePositions[randomNumberBetween0And6]
greyPipe.position = pipePositions[randomNumberBetween0And6]
purplePipe.position = pipePositions[randomNumberBetween0And6]
}