Skip to content

Instantly share code, notes, and snippets.

View UjwalManjunath's full-sized avatar

Ujwal Manjunath UjwalManjunath

View GitHub Profile
@UjwalManjunath
UjwalManjunath / Swap using arithmetic operation
Last active December 17, 2015 13:08
Swapping two variables without using temp.
void swap (int a, int b){
a = a+b; //9 = 4+5
b = a-b; //4 = 9-5
a = a-b; //5 = 9-4
}
@UjwalManjunath
UjwalManjunath / Swap using bit manipulation
Created May 20, 2013 18:57
Swapping two variables without using temp variable
void swap(int a. int b ) {
a= a^b;
b= a^b;
a= a^b; // XOR operation
}
@UjwalManjunath
UjwalManjunath / Formatting to Phone number format
Last active December 19, 2017 18:43
Formatting number to Phone number Format as and when you type it in UItextfield
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
int length = [[self formatNumber:[textField text]] length];
if (length == 10) {
// [self textFieldShouldEndEditing:textField];
if(range.length == 0) {
return NO;
}
}
@UjwalManjunath
UjwalManjunath / co-ordinates to Address
Created July 29, 2013 23:38
Converting Longitude Lattitude to Street Address (IOS/ OBJECTIVE C)
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
CLLocation *currentLocation = [locations lastObject];
if (currentLocation != nil) {
NSLog(@" Longitude: %@",[NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]);
NSLog(@"Latitude: %@",[NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]);
}
[self.locationManager stopUpdatingLocation];
@UjwalManjunath
UjwalManjunath / UITableView Custom Header
Last active December 20, 2015 10:31
adding a custom Header( UIlabel )to a UItableview
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string =@"Enter Email Address";
/* Section header is in 0th index... */
[label setText:string];
view.backgroundColor = [UIColor clearColor];
@UjwalManjunath
UjwalManjunath / UIImageView roundrected
Last active December 20, 2015 11:49
Making UIimage view roundrected
#import <QuartzCore/QuartzCore.h>
UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
// You can even add a border
[l setBorderWidth:4.0];
@UjwalManjunath
UjwalManjunath / Multiplecheckmultiplesection
Created August 1, 2013 19:14
adding checkmark accessary to multiple sections(checking one cell at a time in each section)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:indexPath.section]].accessoryType = UITableViewCellAccessoryCheckmark;
[self deSelectOtherCellsInTableView:tableView Except:indexPath];
}
-(void)deSelectOtherCellsInTableView:(UITableView *)tableView Except:(NSIndexPath *)indexPath{
for(UITableViewCell *cell in [tableView visibleCells]){
NSIndexPath *index = [tableView indexPathForCell:cell];
if(index.section == indexPath.section && index.row != indexPath.row){
@UjwalManjunath
UjwalManjunath / singleSectionSingleCheck
Created August 1, 2013 19:15
adding checkmark to one cell at a time(single section)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
@UjwalManjunath
UjwalManjunath / HTSDReachability.swift
Last active December 7, 2015 16:39
IOS Reachability: Swift 2.0
import UIKit
import SystemConfiguration
public let ReachabilityChangedNotification = "ReachabilityChangedNotification"
class HTSDReachabiltiy: NSObject {
typealias NetworkReachable = (HTSDReachabiltiy) -> ()
typealias NetworkUnreachable = (HTSDReachabiltiy) -> ()
enum NetworkStatus: CustomStringConvertible {
@UjwalManjunath
UjwalManjunath / CollectionViewUtility.swift
Created November 4, 2015 16:50
CollectionViewExtension
import UIKit
extension UICollectionView {
func registerCell(cellType:UICollectionViewCell.Type) {
self.registerNib(cellType.nib(), forCellWithReuseIdentifier: cellType.id())
}
func registerSupplementaryView(classType:UICollectionReusableView.Type, kind:String) {
self.registerNib(classType.nib(), forSupplementaryViewOfKind: kind, withReuseIdentifier: classType.id())