Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make text bold for detailedTextLabel in swift

cell!.textLabel?.text = vehicle["vrn"].string
cell?.detailTextLabel?.text = stateString

I want to display stateString as bold and also tried to use textLabel instead of detailedText but it did not work.

like image 633
Raj Avatar asked Jul 30 '15 13:07

Raj


2 Answers

You can set the font property of the detailTextLabellike so:

cell.detailTextLabel?.font = UIFont.boldSystemFontOfSize(15.0)
like image 143
pbush25 Avatar answered Nov 15 '22 07:11

pbush25


You can use the font property inside the UILabel class.

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

There are other options using the attributedText property but implies a little more of code, something like this:

// 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

I hope this help you.

like image 24
Victor Sigler Avatar answered Nov 15 '22 06:11

Victor Sigler