Omid
Omid

Reputation: 178

Custom font when using MGSwipeTableCell?

I am using the awesome framework MGSwipeTableCell. It works very well but I would like to know how to set a custom UIFont for the title of the buttons.

I tried to do it in the framework files themselves but they are written in Objective-C and I only know Swift.

Here's my code :

cell.leftButtons = [MGSwipeButton(title: "Hello", backgroundColor: UIColor.greenColor(), callback: {
            (sender: MGSwipeTableCell!) -> Bool in

            return true
        }),

Upvotes: 2

Views: 534

Answers (2)

toddg
toddg

Reputation: 2906

Since MGSwipeButton is a subclass of UIButton, you can can change the font like this:

let swipeButton = MGSwipeButton(title: "Hello", backgroundColor: UIColor.greenColor(), callback: {
        (sender: MGSwipeTableCell!) -> Bool in

        return true
    })

swipeButton.titleLabel?.font = UIFont(name: "fontName", size: 14)
cell.leftButtons = [swipeButton]

Upvotes: 1

Özgür Ersil
Özgür Ersil

Reputation: 7013

According to doc. you can use it in that form

cell.leftButtons =  MGSwipeButton(title: "Hello", backgroundColor: UIColor.greenColor(), callback: {
      (sender: MGSwipeTableCell!) -> Bool in
      print("Convenience callback for swipe buttons!")
      return true
    })

Since MGSwipeTableCell extends from UIButton, you can change the font like :

cell.leftButtons!.font =  UIFont(name: "YourfontName", size: 20)

Upvotes: 0

Related Questions