Skip to content

Instantly share code, notes, and snippets.

View leoiphonedev's full-sized avatar

Aman Aggarwal leoiphonedev

View GitHub Profile
@leoiphonedev
leoiphonedev / example.h
Created January 18, 2017 10:30
Declaring our IBOutlets for pagecontrol and UIScrollView
@interface ViewController : UIViewController {
IBOutlet UIPageControl *pageControl;
IBOutlet UIScrollView *scrollView;
}
-(IBAction)changePage:(id)sender;
@end
@leoiphonedev
leoiphonedev / example.m
Created January 18, 2017 10:32
Creating pageview showing 3 images and adding them to scroll view
#define SCROLLWIDTH 279
- (void)viewDidLoad {
scrollView.contentSize=CGSizeMake(SCROLLWIDTH*3,
scrollView.frame.size.height);
scrollView.delegate = self;
for (int i =0; i<=3; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:
CGRectMake(SCROLLWIDTH*i, 0, scrollView.frame.size.width,
scrollView.frame.size.height)];
if (i==0) {
@leoiphonedev
leoiphonedev / example.m
Created January 18, 2017 10:33
Creating IBAction for UIPageControl so that when user tap on UIPageControl it scroll to next page
#pragma mark changePage
-(IBAction)changePage:(id)sender
{
[scrollView scrollRectToVisible:CGRectMake(SCROLLWIDTH*pageControl.currentPage, scrollView.frame.origin.y, SCROLLWIDTH, scrollView.frame.size.height) animated:YES];
}
@leoiphonedev
leoiphonedev / example.m
Created January 18, 2017 10:35
Implementing scroll view delegate so that when user scroll to next page we change indicator of UIPageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {
[self setIndiactorForCurrentPage];
}
-(void)setIndiactorForCurrentPage
{
uint page = scrollView.contentOffset.x / SCROLLWIDTH;
[pageControl setCurrentPage:page];
@leoiphonedev
leoiphonedev / AppDelegate.swift
Created February 26, 2017 13:40
Changes to be made in AppDelegate.swift file of your project during Facbook login integration
//
// AppDelegate.swift
// Facebook-swift
//
// Created by Aman Aggarwal on 26/02/17.
// Copyright © 2017 Aman Aggarwal. All rights reserved.
//
import UIKit
import FacebookCore
@leoiphonedev
leoiphonedev / ViewController-Search-Integration-Using-swift3.swift
Last active March 20, 2017 09:46
Populating our UItableView with the dataArray and adding tagerget to UITextField which wil act as search bar
//
// ViewController.swift
// Search_Using_textField_Swift3
//
// Created by Aman Aggarwal on 3/20/17.
// Copyright © 2017 iostutorialjunction.com. All rights reserved.
//
import UIKit
@leoiphonedev
leoiphonedev / ViewController-Search-Integration-Using-swift3=Part2.swift
Created March 20, 2017 09:50
Search function that will search data fom array as per user textinput
func searchRecordsAsPerText(_ textfield:UITextField) {
searchedArray.removeAll()
if textfield.text?.characters.count != 0 {
for strCountry in countriesArray {
let range = strCountry.lowercased().range(of: textfield.text!, options: .caseInsensitive, range: nil, locale: nil)
if range != nil {
searchedArray.append(strCountry)
}
}
@leoiphonedev
leoiphonedev / Expandable-collapsable-UITableView-using-Swift3-Part1.swift
Created March 23, 2017 10:35
Creating datasource for our Expandable and collapsable UITableView
var dataArray:[Dictionary<String, AnyObject>] = Array()
var indDictionary = [String: AnyObject]()
indDictionary.updateValue("India" as AnyObject, forKey: "parent")
var inCitiesArray:[String] = Array()
inCitiesArray.append("New Delhi")
inCitiesArray.append("Mumbai")
inCitiesArray.append("Chennai")
inCitiesArray.append("Kolkata")
indDictionary.updateValue(inCitiesArray as AnyObject, forKey: "child")
@leoiphonedev
leoiphonedev / Expandable-collapsable-UITableView-using-Swift3-Part2.swift
Last active March 23, 2017 10:50
Full code implementation of Expandable and collapsable UITableView
//
// ViewController.swift
// ExpandableTable
//
// Created by Aman Aggarwal on 3/21/17.
// Copyright © 2017 iostutorialjunction.com. All rights reserved.
//
import UIKit
@leoiphonedev
leoiphonedev / Time-to-Time-Ago-Extension-swift3.swift
Last active March 24, 2017 04:42
Extension for NSDate that will convert Time to time Ago e.g.post is posted "4 days" ago
extension Date {
func getElapsedInterval() -> String {
let interval = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: self, to: Date())
if let year = interval.year, year > 0 {
return year == 1 ? "\(year)" + " " + "year" :
"\(year)" + " " + "years"
} else if let month = interval.month, month > 0 {