Learn iOS and ios
Continue to make the second copy of others
1. First download some fonts and search for "Word Building Studio" online"
2. Put the downloaded font file into the project, and it will be OK.
Not to mention, the effect is as follows:
You can use the following method to retrieve all fonts in the project:
for family in UIFont.familyNames { for font in UIFont.fontNames(forFamilyName: family) { print(font) } }
The Code is as follows:
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 currently authorized individuals are free of charge for non-commercial use \ n, So I donated 1 yuan and 3 fonts for testing \ n, respectively. work room Jin Hei, to the Black and childlike innocence; "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 ("Change font", :. normal) changeBtn. layer. masksToBounds = true changeBtn. layer. cornerRadius = 50.0 changeBtn. addTarget (self, action: # selector (changeFont), :. touchUpInside) self. view. addSubview (changeBtn)} // MARK:-Click Event 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 .}}