Skip to content

Instantly share code, notes, and snippets.

John johncodeos

Block or report user

Report or block johncodeos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@johncodeos
johncodeos / htmltagsinswift.swift
Created May 1, 2016
use HTML tags in uitextview
View htmltagsinswift.swift
extension NSData {
var attributedString: NSAttributedString? {
do {
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
return nil
}
}
@johncodeos
johncodeos / hexStringToUIColor.swift
Last active May 30, 2019
hexStringToUIColor function . e.g var color1 = hexStringToUIColor("#d3d3d3")
View hexStringToUIColor.swift
func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet() as NSCharacterSet).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(cString.startIndex.advancedBy(1))
}
if ((cString.characters.count) != 6) {
return UIColor.grayColor()
}
@johncodeos
johncodeos / specificCorderRadius.swift
Last active May 31, 2019
Tutorial from johncodeos.com
View specificCorderRadius.swift
if #available(iOS 11.0, *){
myUIView.clipsToBounds = true
myUIView.layer.cornerRadius = 5
myUIView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
}else{
let path = UIBezierPath(roundedRect: myUIView.bounds,byRoundingCorners:[.topLeft, .topRight],cornerRadii: CGSize(width: 5, height: 5))
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
myUIView.layer.mask = maskLayer
}
@johncodeos
johncodeos / AppDelegate.swift
Last active Jun 2, 2019
Add 3D Touch to your app and open specific Tab in UITabbar using Swift (https://johncodeos.com/add-3d-touch-to-your-app-using-swift)
View AppDelegate.swift
@available(iOS 9.0, *)
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handled = handleShortcutItem(shortcutItem)
completionHandler(handled)
}
// MARK: - Handling
func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
if shortcutItem.type != "com.johncodeos.3dtouchtutorial.nutrition" && shortcutItem.type != "com.johncodeos.3dtouchtutorial.workout" {
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.johncodeos.appshortcutstutorial">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
View index.js
auth: {
twitter: {
consumer_key: "YOUR_API_KEY", // REQUIRED
consumer_secret: "YOUR_API_SECRET_KEY" // REQUIRED
}
}
@johncodeos
johncodeos / Extensions.swift
Last active Jul 9, 2019
Decode HTML to NSAttributedString without third party library
View Extensions.swift
extension String {
private var convertHtmlToNSAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else {
return nil
}
do {
return try NSAttributedString(data: data,options: [.documentType: NSAttributedString.DocumentType.html,.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
}
catch {
print(error.localizedDescription)
View Extensions.swift
import DTCoreText
extension String {
//Use of DTCoreText library to convert html to String.
public func returnAttributedStringForHTMLString (fontFamily: String, fontName: String, fontSize: CGFloat, textColor: UIColor, textAlignment: CTTextAlignment) -> NSMutableAttributedString {
let encodedData = self.data(using: String.Encoding.utf8)!
let options = [
DTDefaultFontFamily:fontFamily,
DTDefaultFontName: fontName,
DTDefaultFontSize: fontSize,
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.johncodeos.asktorate">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:name=".Application"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.johncodeos.splashscreenexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
You can’t perform that action at this time.