Swift 3 own font for UITableViewCellActionButton

流过昼夜 提交于 2019-12-12 05:40:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/47292403/swift-3-own-font-for-uitableviewcellactionbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!