【发布时间】:2018-05-21 12:48:26
【问题描述】:
Heloo.. 我是 ios、swift 和 xcode 的新手...
我在 swift 文件中有如下逻辑:
class ExpandableHeaderView: UITableViewHeaderFooterView {
func customInit(menu: Menu, section: Int, delegate: ExpandableHeaderViewDelegate) {
//Create Attachment
let imageAttachment = NSTextAttachment()
var textAfterIcon: NSMutableAttributedString
switch menu {
case .HOME:
imageAttachment.image = UIImage(named:"home")
textAfterIcon = NSMutableAttributedString(string: " Home")
:
}
//Set bound to reposition
let imageOffsetY:CGFloat = -3.0;
imageAttachment.bounds = CGRect(
x: 0,
y: imageOffsetY,
width: imageAttachment.image!.size.width,
height: imageAttachment.image!.size.height)
//Create string with attachmen
let attachmentString = NSAttributedString(attachment: imageAttachment)
//Initialize mutable string
let completeText = NSMutableAttributedString(string: "")
//Add image to mutable string
completeText.append(attachmentString)
//Add your text to mutable string
completeText.append(textAfterIcon)
self.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail
self.textLabel?.attributedText = completeText
:
}
}
但我得到的结果如下:
我已经添加了所有NSLineBreakMode.by*,但没有一个是完美的显示图像和标签:[image] Home
我怎样才能去掉textLabel?.attributedText最后的三个点?
真的让我很困惑……
所以,很高兴有人能帮助我...
环境:
- xCode v. 9.3
【问题讨论】:
-
隐藏此
self.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail并检查\ -
您的标签似乎太窄了。您是否为标签添加了任何宽度限制?
-
尝试 textLabel.numberOfLines = 0
-
@chirag90 我尝试添加
textLabel.numberOfLines = 0,但遇到了同样的问题 -
@Anbu.karthik 我禁用/评论了 self.textLabel?.lineBreakMode = NSLineBreakMode.bTruncatingTail` 仍然有同样的问题...