如何快速使detailedTextLabel的文本变为粗体

Raj*_*Raj 5 uitableview detailtextlabel swift

cell!.textLabel?.text = vehicle["vrn"].string
cell?.detailTextLabel?.text = stateString
Run Code Online (Sandbox Code Playgroud)

我想显示stateString为,bold并且还尝试使用textLabel代替,detailedText但是它没有用。

pbu*_*h25 5

您可以这样设置font属性detailTextLabel

cell.detailTextLabel?.font = UIFont.boldSystemFontOfSize(15.0)
Run Code Online (Sandbox Code Playgroud)


Vic*_*ler 5

您可以fontUILabel类中使用该属性。

// You need to set the name of your font here 
cell.detailTextLabel?.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
Run Code Online (Sandbox Code Playgroud)

还有其他使用该attributedText 属性的选项,但意味着需要更多代码,如下所示:

// 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
Run Code Online (Sandbox Code Playgroud)

希望对您有所帮助。