Skip to content

Instantly share code, notes, and snippets.

View AttiaMo's full-sized avatar
🎯
Focusing

Attia Mo AttiaMo

🎯
Focusing
View GitHub Profile
@AttiaMo
AttiaMo / AppDelegate.swift
Last active October 13, 2019 14:35
Find fonts name
for family: String in UIFont.familyNames
{
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}
@AttiaMo
AttiaMo / AppDelegate.swift
Created November 12, 2017 15:25
Setup global appearance of custom font in your whole app.
func setupGlobalAppearance(){
//global Appearance settings
let customFont = UIFont.appRegularFontWith(size: 17)
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: customFont], for: .normal)
UITextField.appearance().substituteFontName = Constants.App.regularFont
UILabel.appearance().substituteFontName = Constants.App.regularFont
UILabel.appearance().substituteFontNameBold = Constants.App.boldFont
}
@AttiaMo
AttiaMo / Extension.swift
Last active December 19, 2017 14:29
Extension file
import Foundation
import UIKit
extension UILabel {
var substituteFontName : String {
get { return self.font.fontName }
set {
if self.font.fontName.range(of:"-Bd") == nil {
self.font = UIFont(name: newValue, size: self.font.pointSize)
}
}
@AttiaMo
AttiaMo / Extension.swift
Last active December 19, 2017 14:18
Use the font
extension UIFont {
class func appRegularFontWith( size:CGFloat ) -> UIFont{
return UIFont(name: "HelveticaNeueW23forSKY-Reg", size: size)!
}
class func appBoldFontWith( size:CGFloat ) -> UIFont{
return UIFont(name: "HelveticaNeueW23foSKY-Bd", size: size)!
}
}
@AttiaMo
AttiaMo / ViewController.swift
Created November 13, 2017 17:50
Use custom font
//self.statusLabel.font = UIFont.UIFont(name: "HelveticaNeueW23forSKY-Reg", size: 17)
// Or you can replace it with
// You can use it for Labels, TextFields, TextViews ..etc
self.statusLabel.font = UIFont.appRegularFontWith(size: 17)
class var hasTopNotch: Bool {
if #available(iOS 11.0, tvOS 11.0, *) {
// with notch: 44.0 on iPhone X, XS, XS Max, XR.
// without notch: 20.0 on iPhone 8 on iOS 12+.
return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
}
return false
}
class var isIphoneXOrBigger: Bool {
// 812.0 on iPhone X, XS.
// 896.0 on iPhone XS Max, XR.
return UIScreen.main.bounds.height >= 812
}