自學 iOS,自學ios

來源:互聯網
上載者:User

自學 iOS,自學ios

繼續做仿造著別人的第二個

1.首先下載 一些字型 網上搜尋 "造字工房" 

2.把下載的相應字型檔放到工程之中,就Ok了

不多說 效果如下

可以下面這個方法 檢索項目裡面所有的字型

   for family in UIFont.familyNames {                        for font in UIFont.fontNames(forFamilyName: family) {                                print(font)                            }                    }

代碼如下

import UIKitclass ViewController: UIViewController {    lazy var contentLabel = UILabel()    lazy var changeBtn = UIButton()    var tag: Int = 0            override func viewDidLoad() {        super.viewDidLoad()       /* for family in UIFont.familyNames {                        for font in UIFont.fontNames(forFamilyName: family) {                                print(font)                            }                    }*/                self.view.backgroundColor = UIColor.black        contentLabel.frame = CGRect(x: 10, y:20, width:UIScreen.main.bounds.size.width - 20, height: 200)        contentLabel.numberOfLines = 0        contentLabel.textColor = UIColor.white        contentLabel.font = UIFont.systemFont(ofSize: 20)        self.view.addSubview(contentLabel)        let content: String = "30 Days Swift\n\n 目前授權個人免費非商業使用\n\n 所以捐款了1元下了3款字型用來做實驗\n\n 分別是造字工房勁黑,致黑和童心;"        contentLabel.text = content                changeBtn.backgroundColor = UIColor.orange        changeBtn.frame.size = CGSize(width: 100, height: 100)        changeBtn.frame.origin = CGPoint(x: UIScreen.main.bounds.size.width/2 - 50, y: UIScreen.main.bounds.size.height - 120)        changeBtn.setTitle("改變字型", for: .normal)        changeBtn.layer.masksToBounds = true        changeBtn.layer.cornerRadius = 50.0        changeBtn.addTarget(self, action: #selector(changeFont), for: .touchUpInside)        self.view.addSubview(changeBtn)     }        //MARK: - 點擊事件    func changeFont() {        var fontName:String        switch tag {        case 0:            fontName = "MFQingShu_Noncommercial-Regular"            tag = 1        case 1:            fontName = "MFYueYuan_Noncommercial-Regular"            tag = 2        case 2:            fontName = "MFWenYan_Noncommercial-Regular"            tag = 3        default:            fontName = "AppleSDGothicNeo-Regular"            tag = 0        }                contentLabel.font = UIFont.init(name: fontName, size: 20)    }            override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.