Skip to content

Instantly share code, notes, and snippets.

View naveedmcs's full-sized avatar
👨‍💻
Nothing is interesting if You are not interested.

Muhammad Naveed naveedmcs

👨‍💻
Nothing is interesting if You are not interested.
View GitHub Profile
@naveedmcs
naveedmcs / MovieListTableViewDataSource.swift
Created December 5, 2019 06:35 — forked from pierosifuentes/MovieListTableViewDataSource.swift
MovieListTableViewDataSource & Delegate
protocol MovieListTableViewDelegate: class {
func showMovieDetail(_ movie: Movie)
}
class MovieListTableViewDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
private weak var delegate: MovieListTableViewDelegate?
private let tableView: UITableView
var movies: [Movie] = [] {
didSet {
@naveedmcs
naveedmcs / gist:ba537060dc40e5a39472a8c04c0ab51b
Created October 24, 2019 06:49 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@naveedmcs
naveedmcs / topMostViewController.swift
Created October 24, 2019 06:40 — forked from db0company/topMostViewController.swift
Get the top most viewController anywhere in the app (typically from the appDelegate). Get the current visible viewController.
extension UIViewController {
func topMostViewController() -> UIViewController {
if self.presentedViewController == nil {
return self
}
if let navigation = self.presentedViewController as? UINavigationController {
return navigation.visibleViewController.topMostViewController()
}
if let tab = self.presentedViewController as? UITabBarController {
if let selectedTab = tab.selectedViewController {
@naveedmcs
naveedmcs / statusbar-color-change.md
Created October 3, 2019 06:49 — forked from WrathChaos/statusbar-color-change.md
iOS 13 and Below How to change Status Bar Color?
if #available(iOS 13.0, *) {
    let app = UIApplication.shared
    let statusBarHeight: CGFloat = app.statusBarFrame.size.height
    
    let statusbarView = UIView()
    statusbarView.backgroundColor = UIColor.red
    view.addSubview(statusbarView)
  
 statusbarView.translatesAutoresizingMaskIntoConstraints = false
@naveedmcs
naveedmcs / PageViewController.swift
Created September 20, 2019 10:41 — forked from miguelfermin/PageViewController.swift
Demonstrates how to add a UIPageViewController to a UIViewController
//
// ViewController.swift
// PageViewController
//
// Created by Miguel Fermin on 5/8/17.
// Copyright © 2017 MAF Software LLC. All rights reserved.
//
import UIKit
@naveedmcs
naveedmcs / XLPagerTabStrip.swift
Created September 19, 2019 13:04 — forked from iAmrSalman/XLPagerTabStrip.swift
[XLPagerTabStrip] #swift #XLPagerTabStrip
import UIKit
import XLPagerTabStrip
class ProfileTabsVC: ButtonBarPagerTabStripViewController {
//MARK: - Life Cycle
override func viewDidLoad() {
setupPager()
super.viewDidLoad()
@naveedmcs
naveedmcs / tableViewActivityIndicator.swift
Created September 19, 2019 12:54 — forked from iAmrSalman/tableViewActivityIndicator.swift
[tableViewActivityIndicator] Add a ActivityIndicator to the bottom of UITableView while loading #swift3 #tableview #paging
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
// print("this is the last cell")
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: tableView.bounds.width, height: CGFloat(44))
self.tableView.tableFooterView = spinner
@naveedmcs
naveedmcs / UITableView+beginRefreshing.swift
Created August 22, 2019 07:14 — forked from mttcrsp/UITableView+beginRefreshing.swift
Extension that allows programmatic pull to refresh
import UIKit
public extension UITableView {
public func beginRefreshing() {
// Make sure that a refresh control to be shown was actually set on the view
// controller and the it is not already animating. Otherwise there's nothing
// to refresh.
guard let refreshControl = refreshControl, !refreshControl.isRefreshing else {
return
@naveedmcs
naveedmcs / UILabelCountLines.swift
Created March 19, 2019 08:59 — forked from fuxingloh/UILabelCountLines.swift
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}
@naveedmcs
naveedmcs / hoge.swift
Created September 27, 2018 19:33 — forked from tanb/hoge.swift
po (print object) Alamofire.Response.data as a String
po String.init(data: response.data!, encoding: NSUTF8StringEncoding)