xib和storyboard文件只是简单的XML文件。与大多数XML文件一样,它们相对容易阅读。为UILabel或UITextField设置字体与添加xml属性一样容易。在这种情况下,使用<fontDescription>
标签。
在Xcode导航器中,导航到xib或storyboard文件,选择“打开方式->源代码”。在示例中,您可以看到一个UITextField:
没有字体属性的TextField
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Ihr Vorname" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="RLF-J9-mQz">
<rect key="frame" x="215.66666666666663" y="16" width="231.33333333333337" height="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="words"/>
</textField>
带有字体属性的文本框
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Ihr Vorname" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="RLF-J9-mQz">
<rect key="frame" x="215.66666666666663" y="16" width="231.33333333333337" height="14"/>
<fontDescription key="fontDescription" name="SourceSansPro-Light" family="Source Sans Pro" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="words"/>
</textField>
将文件保存并在IB中重新打开,就这样!