0

this is my first question here, so feel free to point out anything I might be doing wrong ;)

I'm currently trying to give the UITableViewRowAction-Buttons in my Application a custom font. For that I used David Seeks Answer here and put in in an extension like this:

extension UITableViewCell{

override open func layoutSubviews() {

    super.layoutSubviews()

    for subview in self.subviews {

        for sub in subview.subviews {

            if String(describing: sub).range(of: "UITableViewCellActionButton") != nil {

                for view in sub.subviews {

                    if String(describing: view).range(of: "UIButtonLabel") != nil {

                        if let label = view as? UILabel {

                            label.font = UIFont(name: "CaptureSmallz", size: label.font.pointSize)

}}}}}}}}

It works, but it seems to cut the space of the overlying cell elements: see screenshot Any ideas what I'm doing wrong here?

LarsGvB
  • 267
  • 3
  • 11

1 Answers1

0

Try calling label.sizeToFit(), that should resize things after you've changed the label's font size.

This seems like a good place for a subclass of the UITableViewCell though, to achieve all the customization that you're looking for.

MQLN
  • 2,292
  • 2
  • 18
  • 33
  • thanks that worked. although its not enough to just call label.sizeToFit inside the extension. One needs to this inside the "cellForRowAt"-function for every label inside the cell. But the Indicator is still hidden. Do you know how I call something like sizeToFit for him, too? – LarsGvB Nov 14 '17 at 18:40
  • I already tried "cell.accessoryType = .disclosureIndicator" after the labels were resized but it didn't work. – LarsGvB Nov 14 '17 at 18:55
  • I'd recommend putting all of this code within the 'cellForRow' (better yet: subclass), honestly. Try putting the `cell.accessoryType = .disclosureIndicator` within the 'cellForRow' code. – MQLN Nov 14 '17 at 19:09
  • I had it in the "cellForRowAt" right before returning the cell, but it didnt change anything. Also I just realized that the separator-lines are not visible in between filled cells. – LarsGvB Nov 14 '17 at 19:15
  • The separators get visible after swiping left once to see the RowActionButtons, but the disclosure indicator never shows up. – LarsGvB Nov 14 '17 at 19:34