Swift 3自己的UITableViewCellActionButton字体 [英] Swift 3 own font for UITableViewCellActionButton

查看:96
本文介绍了Swift 3自己的UITableViewCellActionButton字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个问题,请随时指出我可能做错的任何事情;)

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

我目前正在尝试为我的应用程序中的UITableViewRowAction-Buttons提供自定义字体.为此,我使用了 David Seeks在这里回答,并输入了以下扩展名:

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?

推荐答案

尝试调用label.sizeToFit(),它会在更改标签的字体大小后重新调整大小.

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

对于UITableViewCell的子类来说,这似乎是实现您要寻找的所有自定义项的好地方.

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

这篇关于Swift 3自己的UITableViewCellActionButton字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆