如何检查iOS中是否存在方法systemFontOfSize(fontSize:weight :) [英] How to check does method systemFontOfSize(fontSize: weight:) exist in iOS

查看:303
本文介绍了如何检查iOS中是否存在方法systemFontOfSize(fontSize:weight :)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序部署目标是iOS 7.0
我想在iOS 8+的设备上使用方法 systemFontOfSize(fontSize:weight:)。 iOS 7不支持此方法(使用 weight:参数)并且我的应用程序崩溃。特别是对于iOS 7,我想设置Helvetica Light字体而不是SystemFont Light。

My application deployment target is iOS 7.0 I want to use method systemFontOfSize(fontSize: weight:) on devices with iOS 8+. iOS 7 doesn't support this method (with weight: parameter) and my application crashes. Specially for iOS 7 I want to set Helvetica Light font instead of SystemFont Light.

检查它的最佳方法是什么?我需要检查iOS版本还是可以检查方法?如何?

What is the best way to check it? Do I need to check iOS version or I can check the method? how?

我使用swift并尝试

I use swift and tried

if let font = UIFont.systemFontOfSize(12, weight: UIFontWeightLight) 

respondsToSelector 方法。
它对我不起作用。

respondsToSelector method. It didn't work for me.

推荐答案

respondsToSelector 按预期工作:

    let font: UIFont
    if UIFont.respondsToSelector("systemFontOfSize:weight:") {
        println("YES")
        font = .systemFontOfSize(12, weight: UIFontWeightLight)
    }
    else {
        println("NO")
        font = UIFont(name: "HelveticaNeue-Light", size: 12)!
    }

我建议使用HelveticaNeue而不是Helvetica,因为系统字体是 Neue 一个。

And I would recommend HelveticaNeue instead of Helvetica, since the system font is Neue one.

这篇关于如何检查iOS中是否存在方法systemFontOfSize(fontSize:weight :)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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