Skip to content

Instantly share code, notes, and snippets.

Aman Aggarwal leoiphonedev

Block or report user

Report or block leoiphonedev

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
leoiphonedev / ViewControllerDetectTextUILabel-2.swift
Created Aug 7, 2019
Selector for UITapGestre added to UILable and telling us wether user tap on desired text or not
View ViewControllerDetectTextUILabel-2.swift
//MARK:- tappedOnLabel
@objc func tappedOnLabel(_ gesture: UITapGestureRecognizer) {
guard let text = self.lblTermsAndConditions.text else { return }
let privacyPolicyRange = (text as NSString).range(of: "privacy policy")
let termsAndConditionRange = (text as NSString).range(of: "terms and condition")
if gesture.didTapAttributedTextInLabel(label: self.lblTermsAndConditions, inRange: privacyPolicyRange) {
print("user tapped on privacy policy text")
} else if gesture.didTapAttributedTextInLabel(label: self.lblTermsAndConditions, inRange: termsAndConditionRange){
print("user tapped on terms and conditions text")
leoiphonedev / ViewControllerDetectTextUILabel.swift
Created Aug 7, 2019
Adding UITapGestureRecognizer to UILabel
View ViewControllerDetectTextUILabel.swift
self.lblTermsAndConditions.isUserInteractionEnabled = true
let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabel(_ :)))
tapgesture.numberOfTapsRequired = 1
leoiphonedev / UITapGesture.swift
Created Aug 7, 2019
Extension for UITapGesture that contains a function to detect range of particular text in UILabel's text.
View UITapGesture.swift
extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool {
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size:
let textStorage = NSTextStorage(attributedString: label.attributedText!)
// Configure layoutManager and textStorage
leoiphonedev / AdaptableSizeButton.swift
Last active Jul 14, 2019
AdaptableSizeButton class enables the size of button as per the title set to UIButton via overriding intrinsicContentSize of UIButton
View AdaptableSizeButton.swift
class AdaptableSizeButton: UIButton {
override var intrinsicContentSize: CGSize {
let labelSize = titleLabel?.sizeThatFits(CGSize(width: frame.size.width, height: CGFloat.greatestFiniteMagnitude)) ?? .zero
let desiredButtonSize = CGSize(width: labelSize.width + titleEdgeInsets.left + titleEdgeInsets.right, height: labelSize.height + + titleEdgeInsets.bottom)
return desiredButtonSize
leoiphonedev / AppDelegate-localnotification.swift
Created May 20, 2019
Asking for user permissions in order to send hm notifications
View AppDelegate-localnotification.swift
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("User gave permissions for local notifications")
View SendMailAttachment-ViewController-4.swift
// ViewController.swift
// SendMailAttachment
// Created by Aman Aggarwal on 03/12/18.
// Copyright © 2018 Aman Aggarwal. All rights reserved.
import UIKit
import MessageUI
leoiphonedev / SendMailAttachment-ViewController-3.swift
Created Dec 12, 2018
COnformimng to MFMailComposeViewControllerDelegate so that we get notified on user certain action with mail composer view
View SendMailAttachment-ViewController-3.swift
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
leoiphonedev / SendMailAttachment-ViewController-2.swift
Created Dec 12, 2018
Code for presenting mail composer (desfualt) when user tap on send mail button
View SendMailAttachment-ViewController-2.swift
@IBAction func sendEmail(_ sender: Any) {
if MFMailComposeViewController.canSendMail() {
let mailComposer = MFMailComposeViewController()
mailComposer.setSubject("Update about ios tutorials")
mailComposer.setMessageBody("What is the update about ios tutorials on youtube", isHTML: false)
self.present(mailComposer, animated: true
, completion: nil)
} else {
leoiphonedev / SendMailAttachment-ViewController.swift
Created Dec 12, 2018
Creating IBAction for the UIButton in order to send mail when user touch UIButton
View SendMailAttachment-ViewController.swift
@IBAction func sendEmail(_ sender: Any) {
You can’t perform that action at this time.