当前位置: 首页 > news >正文

工程建设标准化期刊网站南昌网站全新开发

工程建设标准化期刊网站,南昌网站全新开发,天津泰达建设集团网站,成都建设网站的ios 自定义字体by Yuichi Fujiki藤木雄一 In this article, youll learn how to create a unified custom look throughout your app with these simple tricks.在本文中#xff0c;您将学习如何使用这些简单的技巧在整个应用程序中创建统一的自定义外观。 我们想做什么 (Wh…ios 自定义字体by Yuichi Fujiki 藤木雄一 In this article, youll learn how to create a unified custom look throughout your app with these simple tricks. 在本文中您将学习如何使用这些简单的技巧在整个应用程序中创建统一的自定义外观。 我们想做什么 (What we want to do) In iOS, there is a mechanism called UIAppearance to define an app’s global configuration. For example, you can set a consistent background color of the navigation bar with just one line : 在iOS中有一种名为UIAppearance的机制可以定义应用程序的全局配置。 例如您可以只用一行设置导航栏的一致背景色 UINavigationBar.appearance().barTntColor UIColor.blueHowever, if you apply the same approach to the font like this: 但是如果您对字体应用相同的方法如下所示 UILabel.appearance().font UIFont(named: Gills Sans, size: 14)all the UILabel instances will indeed have “Gills Sans”, but with 14pt size as well. I don’t think any app would want to have only 14pt fonts throughout the app. Since UIFont always needs the size information to be initialized, there is no standard way in UIKit to just change the typeface without affecting the size. 所有UILabel实例的确将具有“ Gills Sans” 但大小也为14pt 。 我认为任何应用程序都不希望整个应用程序中只有 14pt字体。 由于UIFont始终需要初始化大小信息因此UIKit 没有标准的方法来更改字体而不影响大小。 But, don’t you want to change the font typeface without hunting down all the Swift files and Interface Builder files? Imagine you have an app with tens of screens and the product owner decides to change the font for the entire app. Or your app wants to cover another language, and you want to use another font for the language because it would look better. 但是您是否不想在不搜索所有Swift文件和Interface Builder文件的情况下更改字体字体 假设您有一个带有数十个屏幕的应用程序产品负责人决定更改整个应用程序的字体。 或者您的应用想要覆盖另一种语言并且您想要使用另一种字体作为该语言因为它看起来会更好。 This short article explains how you can do that with just several lines of code. 这篇简短的文章说明了如何仅用几行代码就能做到这一点。 UIView扩展 (UIView Extension) When you create UIView extension and declare a property with objc modifier, you can set that property through UIAppearance. 创建UIView扩展并使用objc修饰符声明属性时可以通过UIAppearance设置该属性。 For example, if you declare a UILabel extension property substituteFontName like this: 例如如果你声明UILabel扩展属性substituteFontName是这样的 You can call it in AppDelegate.application(:didFinishLaunching...) 您可以在AppDelegate.application(:didFinishLaunching...)调用它 UILabel.appearance().substituteFontName Gills SansAnd voilà, all UILabel will be in the “Gills Sans” font with appropriate sizes. ? 而且所有UILabel都将使用适当大小的“ Gills Sans”字体。 但是您也想使用粗体字不是吗 (But you want to use bold font as well, don’t you?) Life is good so far, but what if you want to specify two different variations of the same font, like bold font? You would think you can just add another extension property substituteBoldFontName and call it like this, right? 到目前为止生活还不错但是如果要指定同一字体的两个不同变体(如粗体字体)怎么办 您会以为您可以添加另一个扩展属性substituteBoldFontName并这样称呼对吗 UILabel.appearance().substituteFontName fontNameUILabel.appearance().substituteBoldFontName boldFontNameNot that easy. If you do this, then all the UILabel instances show up in bold font. I will explain why. 没那么容易。 如果执行此操作则所有 UILabel实例均以粗体显示。 我将解释原因。 It seems that UIAppearance is just calling all the setter methods of the registered properties in the order they were registered. 似乎UIAppearance只是按照注册属性的注册顺序调用它们的所有setter方法。 So if we implemented the UILabel extension like this: 因此如果我们这样实现UILabel扩展 then setting the two properties through UIAppearance results in the code sequence similar to the following at every UILabel initialization under the hood. 然后通过UIAppearance设置这两个属性UIAppearance导致代码序列类似于在UIAppearance每次UILabel初始化时的代码序列。 font UIFont(name: substituteFontName, size: font.pointSize)font UIFont(name: substituteBoldFontName, size: font.pointSize)So, the first line is overwritten by the second line and you are going to have bold fonts everywhere. ? 因此第一行被第二行覆盖您到处都会有粗体。 你能为这个做什么 (What can you do about it?) In order to solve this issue, we can assign proper font style based on the original font style ourselves. 为了解决此问题我们可以根据自己的原始字体样式分配适当的字体样式。 We can change our UILabel extension as follows: 我们可以如下更改UILabel扩展名 Now, the code sequence that is called at UILabel initialization will be as follows, and only one of the two font assignment will be called in a condition. 现在在UILabel初始化中调用的代码序列如下并且在条件中将仅调用两种font分配中的一种。 if font.fontName.range(of: Medium) nil { font UIFont(name: newValue, size: font.pointSize)}if font.fontName.range(of: Medium) ! nil { font UIFont(name: newValue, size: font.pointSize)}As a result, you will have an app with beautifully unified text style while regular and bold fonts co-exist, yay! ? 结果您将拥有一个具有精美统一文本样式的应用程序而常规字体和粗体字体并存 You should be able to use the same logic to add more styles like italic fonts as well. Also, you should be able to apply the same approach to another control like UITextField. 您应该能够使用相同的逻辑来添加更多样式例如斜体字体。 同样您应该能够将相同的方法应用于另一个控件例如UITextField 。 Hope this helps fellow iOS devs, happy coding!! 希望这对其他iOS开发人员有所帮助祝您编程愉快 翻译自: https://www.freecodecamp.org/news/how-to-use-consistent-custom-font-in-an-ios-app-e07b1ddb7a7c/ios 自定义字体
http://www.zqtcl.cn/news/813942/

相关文章:

  • 无锡网站营销公司简介最专业网站建设公司首选
  • 中文网站建设小组ios开发者账号申请
  • 月熊志网站福州建网站 做网页
  • 不同的网站有不同的风格宁波设计网站公司
  • 学校网站制作平台电子政务门户网站建设代码
  • 产品推广的网站怎么做网站标题与关键词
  • 青蛙网站建设wordpress修改logo
  • 网站套餐方案引擎搜索对人类记忆的影响
  • 滨州市滨城区建设局网站扎金花网站怎么做
  • 网站开发中视屏怎样编辑到网页上常州建站公司模板
  • 视频涉台互联网网站怎么做1cpu0.5g服务器用来做网站
  • 营销型网站设计官网怎么做网站优化 sit
  • 怎样获得做网站的客户免费企业网站程序上传
  • 新闻排版设计用什么软件网站seo诊断分析
  • 手机网站端域名怎样做解析一诺摄影设计
  • 网站开发行业竞争大吗郑州百度推广代运营公司
  • mvc4做网站五设计一个公司网站多少钱
  • 在什么网站可以做外贸出口劳保鞋北京 代理前置审批 网站备案
  • 邢台建设企业网站房地产宣传推广方案
  • 建设机械网站案例分析餐饮vi设计开题报告范文
  • 做本地生活网站深圳建设工程信息网站
  • C2C电商网站做博客的网站有哪些
  • 住房和城乡建设部网站 事故安微省建设厅田网站
  • 百度一下你就知道官页淘宝seo搜索引擎优化
  • 网站平台维护phpwind做的网站
  • 网站怎么做移动适配怎么样才算是一个网站页面
  • 做pc端网站策划百度网站建立
  • 高级网站开发技术青岛网站建设方案服务
  • 深圳公司网站建设设房地产网址大全
  • 怎么里ip做网站女生学广告学后悔死了