如何在swift中为detailedTextLabel设置粗体文本
我想将如何在swift中为detailedTextLabel设置粗体文本,swift,uitableview,detailtextlabel,Swift,Uitableview,Detailtextlabel,我想将stateString显示为bold,并尝试使用textLabel而不是detailedText,但无效。您可以设置detailedtextlabel的字体属性,如下所示: cell!.textLabel?.text = vehicle["vrn"].string cell?.detailTextLabel?.text = stateString 您可以在UILabel类中使用该属性 cell.detailTextLabel?.font = UIFont.boldSystemFontOf
stateString
显示为bold
,并尝试使用textLabel
而不是detailedText
,但无效。您可以设置detailedtextlabel
的字体属性,如下所示:
cell!.textLabel?.text = vehicle["vrn"].string
cell?.detailTextLabel?.text = stateString
您可以在UILabel
类中使用该属性
cell.detailTextLabel?.font = UIFont.boldSystemFontOfSize(15.0)
还有其他使用该属性的选项,但这意味着更多的代码,如下所示:
// You need to set the name of your font here
cell.detailTextLabel?.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
我希望这对您有所帮助。如果您想使用故事板加粗文本标签,只需在属性检查器中选择与该文本颜色相同的阴影颜色即可。这对我有用试试看 答案不正确,您需要设置.font属性而不是.text正确答案:cell?.detailTextLabel?.textColor=UIColor.blackColor()您是对的,应该是font,而不是text,我的错。但是仅仅将文本颜色设置为黑色并不能使其变为粗体。。。
// Define attributes to set
let labelFont = UIFont(name: "HelveticaNeue-Bold", size: 16)
let attributes :Dictionary = [NSFontAttributeName : labelFont]
// Create the attributed string
var attrString = NSAttributedString(string: "textOfYourLabel", attributes:attributes)
cell.detailTextLabel?.attributedText = attrString