iPhone system font

前端 未结 12 540
日久生厌
日久生厌 2020-12-12 18:31

What is the name of the default system font on the iPhone?

I would like to retrieve this for customizing a UIView.

12条回答
  •  再見小時候
    2020-12-12 19:26

    Swift

    You should always use the system defaults and not hard coding the font name because the default font could be changed by Apple at any time.

    There are a couple of system default fonts(normal, bold, italic) with different sizes(label, button, others):

    let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
    let font2 = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
    let font3 = UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)
    

    beaware that the default font size depends on the target view (label, button, others)

    Examples:

    let labelFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
    let buttonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
    let textFieldFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)
    

提交回复
热议问题