Skip to content

Instantly share code, notes, and snippets.

View startupcode's full-sized avatar

Rakesh Kumar startupcode

View GitHub Profile
@startupcode
startupcode / IoniconTitleUIButton.swift
Last active August 21, 2021 18:11
Swift - add ionicon icons in UIButton
//Swift - Using Iconicon icons in UIButton as Title.
//Ionicon.swift file needs to be added. It is attached here for reference
//Also you will require font file "ionicons.ttf"
//Calling the method
var btnTick = getButtonWithIconicon(CGRectMake(8, 12, 25, 25), title: String.ioniconWithCode("ion-checkmark-round")!, titleSize: UIFont.ioniconOfSize(25), titleColor: .greenColor())
func getButtonWithIconicon (coordinates: CGRect, title btnTitle: String, titleSize btnTitleSize: UIFont, titleColor btnTitleColor: UIColor) -> UIButton {
@startupcode
startupcode / extend-uibutton-save-object.swift
Created July 8, 2016 08:32
Swift - Extend UIButton to save an object
private var associationKey: UInt8 = 0
extension UIButton {
var objectRef: String! {
get {
return objc_getAssociatedObject(self, &associationKey) as? String
}
set(newValue) {
objc_setAssociatedObject(self, &associationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
@startupcode
startupcode / HtmlToAttributedString.swift
Last active October 3, 2023 01:08
Swift - Assign HTML to NSAttributedString with custom FONT
//Usage
lbl.attributedText = htmlToAttributedString ("html text")
//Assign attributed string
func htmlToAttributedString(string : String) -> NSAttributedString{
var attribStr = NSMutableAttributedString()
do {//, allowLossyConversion: true
attribStr = try NSMutableAttributedString(data: string.dataUsingEncoding(NSUnicodeStringEncoding)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
@startupcode
startupcode / Checkbox-Swift.swift
Last active September 14, 2018 06:22
Swift "Checkbox" class extending UIButton.
//Here whenever isChecked value is assigned, it will update the text as per true or false condition
class CheckBox: UIButton {
var mySelectedAttributedTitle = NSAttributedString(string:" TRUE", attributes: [NSFontAttributeName: UIFont.ioniconOfSize(26), NSForegroundColorAttributeName : UIColor.blackColor()])
// Bool property
var isCheck: Bool = false {
didSet{
if isCheck == true {
//Assign true case image/text to the button like as follows
@startupcode
startupcode / StringToBool-Swift-Extension.swift
Created July 5, 2016 08:34
Swift "String" Extension to convert string values in Bool. You can add any value in "Case" for true and false and it will convert it to Bool.
extension String {
func convertToBool() -> Bool? {
switch self {
case "true", "1", "yes":
return true
case "false", "0", "no":
return false
default:
return nil
}