glyuck / GlyuckDataGrid

DataGridView (multicolumn tables) for iOS based on UICollectionView
MIT License
120 stars 35 forks source link

Change font size and color #1

Closed utkbansal closed 8 years ago

utkbansal commented 8 years ago

How can I change the font size and the color of the text in a cell? I am using the example in the README.

glyuck commented 8 years ago

Check SimpleDataGridViewController and dataGridView:cellForItemAtIndexPath method:

func dataGridView(dataGridView: DataGridView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = dataGridView.dequeueReusableCellWithReuseIdentifier(DataGridView.ReuseIdentifiers.defaultCell, forIndexPath: indexPath) as! DataGridViewContentCell
    cell.textLabel.text = "Some text"
    cell.textLabel.font = UIFont.systemFontOfSize(20)
    if indexPath.dataGridColumn == 0 {
        cell.textLabel.textColor = UIColor.redColor()
    } else {
        cell.textLabel.textColor = UIColor.darkTextColor()
    }
    // ... further customization
    return cell
}

You can also use UIAppearance to change all cells appearance:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let labelAppearance = UILabel.glyuck_appearanceWhenContainedIn(DataGridViewContentCell.self)
    labelAppearance.appearanceFont = UIFont.systemFontOfSize(17, weight: UIFontWeightLight)
    labelAppearance.appearanceTextColor = UIColor.darkGrayColor()
    // ...
    return true
}

Please, note: you need to use appearanceFont and appearanceTextColor properties for customizing UILabel via UIAppearance (see UILabel (AppearanceSelectors) extension)