• <i id='rpusA'><tr id='rpusA'><dt id='rpusA'><q id='rpusA'><span id='rpusA'><b id='rpusA'><form id='rpusA'><ins id='rpusA'></ins><ul id='rpusA'></ul><sub id='rpusA'></sub></form><legend id='rpusA'></legend><bdo id='rpusA'><pre id='rpusA'><center id='rpusA'></center></pre></bdo></b><th id='rpusA'></th></span></q></dt></tr></i><div id='rpusA'><tfoot id='rpusA'></tfoot><dl id='rpusA'><fieldset id='rpusA'></fieldset></dl></div>
  • <legend id='rpusA'><style id='rpusA'><dir id='rpusA'><q id='rpusA'></q></dir></style></legend>

      <tfoot id='rpusA'></tfoot>

      • <bdo id='rpusA'></bdo><ul id='rpusA'></ul>

      <small id='rpusA'></small><noframes id='rpusA'>

      1. 如何在 iOS 8 中通过外观代理设置 UIButton 字体?

        How to set UIButton font via appearance proxy in iOS 8?(如何在 iOS 8 中通过外观代理设置 UIButton 字体?)

        <small id='iNjFQ'></small><noframes id='iNjFQ'>

          <bdo id='iNjFQ'></bdo><ul id='iNjFQ'></ul>

            <tbody id='iNjFQ'></tbody>

          <tfoot id='iNjFQ'></tfoot>
            <i id='iNjFQ'><tr id='iNjFQ'><dt id='iNjFQ'><q id='iNjFQ'><span id='iNjFQ'><b id='iNjFQ'><form id='iNjFQ'><ins id='iNjFQ'></ins><ul id='iNjFQ'></ul><sub id='iNjFQ'></sub></form><legend id='iNjFQ'></legend><bdo id='iNjFQ'><pre id='iNjFQ'><center id='iNjFQ'></center></pre></bdo></b><th id='iNjFQ'></th></span></q></dt></tr></i><div id='iNjFQ'><tfoot id='iNjFQ'></tfoot><dl id='iNjFQ'><fieldset id='iNjFQ'></fieldset></dl></div>
              1. <legend id='iNjFQ'><style id='iNjFQ'><dir id='iNjFQ'><q id='iNjFQ'></q></dir></style></legend>

                  本文介绍了如何在 iOS 8 中通过外观代理设置 UIButton 字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试通过外观代理设置 UIButton 的字体.但这似乎不起作用.这是我尝试过的.

                  I tried to set the font of UIButton via appearance proxy. But it doesn't seem to work. This is what I tried.

                  UIButton.appearance().titleFont = UIFont(name: FONT_NAME_DEFAULT, size:20.0)UIButton.appearance().titleLabel?.font = UIFont(name: FONT_NAME_DEFAULT, size:20.0)

                  iOS 8中如何通过外观代理设置UIButton字体?

                  How to set UIButton font via appearance proxy in iOS 8 ?

                  编辑:在 vaberer 的 link:我很惊讶 UIButton 没有任何 UI_APPEARANCE_SELECTOR 属性,但符合 UIAppearance 协议."

                  EDIT: Found in vaberer's link: "I'm surprised that UIButton doesn't have any UI_APPEARANCE_SELECTOR properties, yet conforms to the UIAppearance protocol."

                  推荐答案

                  在支持主题的应用程序中遇到了同样的问题.

                  Had the same problem with a theme-able app.

                  // UIButton+TitleLabelFont.swift
                  
                  import UIKit
                  
                  extension UIButton {
                      var titleLabelFont: UIFont! {
                          get { return self.titleLabel?.font }
                          set { self.titleLabel?.font = newValue }
                      }
                  }
                  

                  2.然后设置 UIButton 外观原型对象

                  2. Then setup the UIButton appearance prototype object

                  class Theme {
                      static func apply() {
                         applyToUIButton()
                         // ...
                      }
                  
                      // It can either theme a specific UIButton instance, or defaults to the appearance proxy (prototype object) by default
                      static func applyToUIButton(a: UIButton = UIButton.appearance()) {
                         a.titleLabelFont = UIFont(name: FONT_NAME_DEFAULT, size:20.0)
                         // other UIButton customizations
                      }
                  }
                  

                  3.在应用委托中删除主题设置

                  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
                      Theme.apply()
                  
                      // ...
                  
                      return true
                  }
                  

                  如果您早先预加载内容(lazy var 来自情节提要的 VC),最好不要使用应用委托设置主题内容,而是像这样在覆盖初始化程序中设置主题内容:

                  If you're preloading stuff (lazy var VCs from storyboards) earlier, it may be better to instead of using app delegate setup the theme stuff in an override initializer like so:

                  private var _NSObject__Theme_apply_token: dispatch_once_t = 0
                  
                  extension NSObject {
                      override public class func initialize() {
                          super.initialize()
                          // see also: https://stackoverflow.com/questions/19176219/why-am-i-getting-deadlock-with-dispatch-once
                          var shouldRun = false
                          dispatch_once(&_NSObject__Theme_apply_token) {
                              shouldRun = true
                          }
                          if shouldRun {
                              Theme.apply()
                          }
                      }
                  }
                  

                  这篇关于如何在 iOS 8 中通过外观代理设置 UIButton 字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UIButton title text color(UIButton 标题文本颜色)
                  Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                  Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                  How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  UIButton remove all target-actions(UIButton 删除所有目标动作)
                  <tfoot id='smUJE'></tfoot>
                  <legend id='smUJE'><style id='smUJE'><dir id='smUJE'><q id='smUJE'></q></dir></style></legend>
                    <bdo id='smUJE'></bdo><ul id='smUJE'></ul>

                    1. <i id='smUJE'><tr id='smUJE'><dt id='smUJE'><q id='smUJE'><span id='smUJE'><b id='smUJE'><form id='smUJE'><ins id='smUJE'></ins><ul id='smUJE'></ul><sub id='smUJE'></sub></form><legend id='smUJE'></legend><bdo id='smUJE'><pre id='smUJE'><center id='smUJE'></center></pre></bdo></b><th id='smUJE'></th></span></q></dt></tr></i><div id='smUJE'><tfoot id='smUJE'></tfoot><dl id='smUJE'><fieldset id='smUJE'></fieldset></dl></div>
                        <tbody id='smUJE'></tbody>

                        <small id='smUJE'></small><noframes id='smUJE'>