Showing posts with label ios. Show all posts
Showing posts with label ios. Show all posts

Tuesday, 18 March 2014

uiwebview Rotation Problem

Best solution: Set constraints on the UIWebView. When the View rotated, the space constraints should automatically adjust.

Wednesday, 5 March 2014

Setting custom UITableViewCells height

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}






 

How to change font size of a row in tableview (iOS Developer)

    cell.textLabel.font = [UIFont systemFontOfSize:12];

Tuesday, 4 March 2014

UITableView with Multiple Sections


 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 2 ;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      if (section==0)
      {
             return [array1 count];
      }
      else{
             return [array2 count];
      }
 }

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

 if(section == 0)
      return @"Section 1";
 if(section == 1)
      return @"Section 2";
 }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }

 if (indexPath.section==0) {
     ObjectData *theCellData = [array1 objectAtIndex:indexPath.row];

Monday, 3 March 2014

Using fontawesome for objective-C iOS Developer

If you like to use fontawesome in your objective C App, I have find a perfect project on github, this is the link:

https://github.com/alexdrone/ios-fontawesome


FontAwesome+iOS

Font awesome is an iconic font. Read more about it on http://fortawesome.github.com/Font-Awesome/
This category brings this great iconic font on iOS.

Usage

First, make sure you have FontAwesome.ttf bundled in your project and that UIAppFonts key in the project's plist file contains a String item named FontAwesome.ttf Then add the NSString+FontAwesome category to the project.
UILabel *label = [...]
label.font = [UIFont fontWithName:kFontAwesomeFamilyName size:20];
You can now use enums for all the different iconic characters
label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];
or you can reference them by using the class identifiers listed here http://fortawesome.github.com/Font-Awesome/#all-icons
label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-github"];
That's it! For further information have a look to the small demo project!

FAImageView

FAImageView is now extended and contains a new property called defaultView that is shown when the image is set to nil. It is possible to use one the font-awesome icon as a default placeholder for an image view.
FAImageView *imageView = [[FAImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, 100.f, 100.f)];
imageView.image = nil;
[imageView setDefaultIconIdentifier:@"fa-github"];

License

This project uses the FontAwesome fix made by Pit Garbe that you can find at https://github.com/leberwurstsaft/FontAwesome-for-iOS Version 2.0 of the Font Awesome font, CSS, and LESS files are licensed under CC BY 3.0: http://creativecommons.org/licenses/by/3.0/ A mention of 'Font Awesome - http://fortawesome.github.com/Font-Awesome' in human-readable source code is considered acceptable attribution (most common on the web). If human readable source code is not available to the end user, a mention in an 'About' or 'Credits' screen is considered acceptable (most common in desktop or mobile software)

UIFont Class Reference

Overview

The UIFont class provides the interface for getting and setting font information. The class provides you with access to the font’s characteristics and also provides the system with access to the font’s glyph information, which is used during layout. You use font objects by passing them to methods that accept them as a parameter.
You do not create UIFont objects using the alloc and init methods. Instead, you use class methods of UIFont, such as preferredFontForTextStyle:, to look up and retrieve the desired font object. These methods check for an existing font object with the specified characteristics and return it if it exists. Otherwise, they create a new font object based on the desired font characteristics.
Font objects are immutable and so it is safe to use them from multiple threads in your app.

Read more: https://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html

Sunday, 2 March 2014

Expanding and Collapsing table view cells in ios

Find a great code for expanding and collapsing table view on apple developer webiste. This is the link:
https://developer.apple.com/library/ios/samplecode/TableViewUpdates/Introduction/Intro.html


"TableViewUpdates" demonstrates how you can use animated updates to open and close sections of a table view for viewing, where each section represents a play, and each row contains a quotation from the play. It also uses gesture recognizers to respond to user input: * A UITapGestureRecognizer to allow tapping on the section headers to expand the section; * A UIPinchGestureRecognizer to allow dynamic changes to the height of table view rows; and * A UILongPressGestureRecognizer to allow press-and-hold on table view cells to initiate an email of the quotation.

Change cell color when selected ios code

    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds] ;
    cell.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor] ;



Setup font for the whole app - iOS Developer

 Article Source Link: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Step 1: Include your fonts in your XCode project
Most commonly, you’ll have a TTF or OTF font that you’ll want to use with all of your UILabels or UITextViews in your app. Well, the first step is to include these fonts into your XCode project.

I commonly keep all of my app resources such as images or fonts in their own directory called “Resources”. I find that this helps me stay organized as projects get much more complex and there are a lot of files. Whatever your case may be, either drag and drop your font file(s) into your XCode file tree or right click and “Add Files To…” to select your fonts.

Adding Custom Fonts to XCode Dialog Box
Make sure that the target you want to use your font in is checked!


Step 2: Make sure that they’re included in the target
The next thing to do is to make sure that they’re resources and included in your build target that you want to use the fonts in.

Checking That Your Custom Font Is Included In Your Target
Make sure that the target you want to use your font in is checked under “Target Membership”


Step 3: Double check that your fonts are included as Resources in your bundle
This should not be a problem but sometimes when you’re having trouble getting your font face to show up, this can be a source of headache so let’s double check now to rule it out as a potential pitfall.

this can be a source of headache

Go to your project Build Phases pane by highlighting the XCode project file in your solution explorer and on the right hand side, select “Build Phases”. You’ll see that one of the sections you can expand is “Copy Bundle Resources”. Open that list and make sure that your fonts are included in that list.

Checking That Your iOS Custom Font Is a Resource In The Bundle
Ensure that your fonts are in the “Copy Bundle Resources” list


Step 4: Include your iOS custom fonts in your application plist
The next thing to do is to modify your app’s plist to include these font faces. By default, your plist will be named something like [appname]-Info.plist and will reside in the “Supporting Files” folder if you haven’t moved it.

Open it and add a new row called “Fonts provided by application” which will be an array that you need to add all the filenames of the fonts you want to use. In my case, it was three of the Neutraface 2 Display fonts as you can see in the screenshot below. Be careful to include the extension and make sure that you don’t perform any typos here. That’s another common problem, as simple as it may seem.

Adding Your Custom iOS Fonts To Your App Plist
See the above screenshot on the key that you need to add, followed by the filenames of the fonts you want to include in your iOS app

…make sure that you don’t perform any typos here. That’s another common problem


Step 5: Find the name of the font
This is a common pitfall for many people trying to include custom fonts into their iOS app. This was something that eluded me before as well and it’s the fact that when you specify which font you want to use, you’re not specifying the file name but rather, the font name. The tricky part is that the font name may not be what you expect. It could be very different than any of the visible font names that you can see.

So in order to easily find the name of the font that you want to use, you can output something to the console window and see for yourself.

The tricky part is that the font name may not be what you expect

Add this snippet of code to log all the fonts available to your app in the console.

1
2
3
4
5
6
7
8
9
for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);
       
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}
Once you run your app, you’ll get the list of fonts displayed in your console log. Then its just a matter of finding your custom font in the list and getting the font names.

Finding The Font Names For Your Custom Fonts
Logging all fonts and finding the font names for your custom font

In the screenshot above, as you can see the font name I needed was Neutraface2Display-Bold. This font name was no where to be found in the font properties or from the OSX font viewer. Remember to get rid of that code snippet after you find the font name that you need!


Step 6: Use UIFont and specify the name of the font
And finally, you can simply display your custom font using UIFont and whatever UILabel or text view you want.

1
2
3
4
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"Using Custom Fonts";
label.font = [UIFont fontWithName:@"Neutraface2Display-Titling" size:20];
Sample of Displaying The Custom Font in the iOS Simulator
Sample of using custom fonts in your iOS App!

Tuesday, 25 February 2014

View Controller Transitions iOS7


If you like to learn about animatedtransitioning this is the best blog that I have find, explains it very well: http://www.objc.io/issue-5/view-controller-transitions.html


View Controller Transitions
Issue #5 iOS 7, October 2013
By Chris Eidhof

One of the most exciting iOS 7 features for me is the new View Controller Transitioning API. Before iOS 7, I would also create custom transitions between view controllers, but doing this was not really supported, and a bit painful. Making those transitions interactive, however, was harder.

Before we continue with the article, I’d like to issue a warning: this is a very new API, and while we normally try to write about best practices, there are no clear best practices yet. It’ll probably take a few months, at least, to figure them out. This article is not so much a recommendation of best practices, but rather an exploration of a new feature. Please contact us if you find out better ways of using this API, so we can update this article.

Before we look at the API, note how the default behavior of navigation controllers in iOS 7 changed: the animation between two view controllers in a navigation controller looks slightly different, and it is interactive. For example, to pop a view controller, you can now pan from the left edge of the screen and interactively drag the current view controller to the right.

That said, let’s have a look at the API. What I found interesting is the heavy use of protocols and not concrete objects. While it felt a bit weird at first, I prefer this kind of API. It gives us as programmers much more flexibility. First, let’s try to do a very simple thing: having a custom animation when pushing a view controller in a navigation controller (the sample project for this article is on github). To do this, we have to implement one of the new UINavigationControllerDelegate methods:

- (id<UIViewControllerAnimatedTransitioning>)
                   navigationController:(UINavigationController *)navigationController
        animationControllerForOperation:(UINavigationControllerOperation)operation
                     fromViewController:(UIViewController*)fromVC
                       toViewController:(UIViewController*)toVC
{
    if (operation == UINavigationControllerOperationPush) {
        return self.animator;
    }
    return nil;
}

Read the rest of the article here : http://www.objc.io/issue-5/view-controller-transitions.html



Sunday, 29 September 2013

Designing app for iOS 7

Deference, clarity and depth are the main themes for iOS 7 development. Focus on core functionalities and content and keep the design simple.

Provide clarity:
  1. Use plenty of negative space, negative space make important content more noticeable. 
  2. Let color simplify the UI.
  3. Ensure legibility by using the system fonts. 
  4. Embrace borderless buttons.   

Content is at the heart of iOS 7: 
  1. Take advantage of the whole screen, let content extend to the edges.
  2. Reconsider visual indicators of physicality and realism, avoid heavy UI elements, keep it simple, focus on content and let the UI have the supporting role. 
  3. Let translucent UI elements hint at the content behind them.



Wednesday, 7 August 2013

How to get user's current location in your app (iOS programming)

To get current location in iOS:

---> #import <coreLocation/coreLocation.h>
1- Create an instance of CLLocationManager
2- Assign a delegate to the CLLocationManager object
3- Set desiredAccuracy & distanceFilter
4- Call startUpdatingLocation
5- locationManager reports the event to this method ---> locationManager:didUpdateLocations (iOS 6 & Later)


Sample Code:


-----> .h File
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface infinityViewController : UIViewController <CLLocationManagerDelegate>{

    CLLocationManager *locationManager;
}
@end

----> .m File

#import "infinityViewController.h"


@interface infinityViewController ()


@end



@implementation infinityViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
   
    [self getCurrentLocation];
   
   
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getCurrentLocation

{
   
    if (locationManager == nil  )
       
        locationManager = [[CLLocationManager alloc] init];
   
   
   
    locationManager.delegate = self;
   
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

   
    locationManager.distanceFilter = 400;
   
   
   
    [locationManager startUpdatingLocation];
   
}


- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations {
       
    CLLocation* currentLocation = [locations lastObject];
   
    NSDate* eventDate = currentLocation.timestamp;
   
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
   
    if (abs(howRecent) < 20.0) {
       
       
        NSLog(@"Latitude Value: %+.6f\n",currentLocation.coordinate.latitude);
                   
        NSLog(@"Longitude Value %+.6f\n",currentLocation.coordinate.longitude);
       
    }
   
}

@end

written by: infinitywebseo 

Tuesday, 2 July 2013

Write Objective C code for absolute beginner (Quick Guide)

Objective C is basically object oriented C, its an extend C programming language. So, it has the basic syntax as C, are the primitive types, structures, functions, control flows (if, else, for, ...), pointers, and libraries.

What objective C adds to C ---> Defining new class, instance methods, methods invocations, automatic synthesizing of accessor methods, static and dynamic typing, blocks plus protocols and categories.

Lets start with classes and objects, a class encapsulates the data and defines actions to operate on that data and object is run time instance of the class.

Class extensions in objective C:
  • .h is the header file.
  • .m is the implementation file.
  • .mm is the implementation file if you are using C++ in your code as well.
 .h file:

@interface className : parentClassName

{
    // Member variables

}

 //method declarations

@end





.m file: 

// #import directive is like #include directive in C the difference is that #import directive makes sure // that the same header file never included more than once.

#import className.h

@implementation className
{
   

}

Objective C allows both static and dynamic typing:

className *object1;  // Static typing
id       object2;  // Dynamic typing
NSString *myName;  // static typing
 
 
Methods in objective C ----> Instance Methods and Class Methods
For instance method you need to create an instance of the class first then use the method. But Class Method dose not requires an instance of the class to be receiver of the message.

Instance method declaration is preceded by a minus sign (-). For Class Methods, its a plus sign (+).
 
written by: infinitywebseo 

Monday, 1 July 2013

What is autoreleasepool?

@autoreleasepool {

 return UIApplicationMain(argc, argv, nil, NSStringFromClass([yourAppNameAppDelegate class]));

}

Basically autoreleasepool supports automatic reference counting, which provides automatic object-life time management for your iOS application.

In simple words it just makes sure that objects are around as long as they are needed in your app and not longer.

written by: infinitywebseo 

Wednesday, 26 June 2013

How to create iCloud entitlements file manually?

Creating entitlements file manually is very simple, open the text editor and just copy and paste the following lines of code: (save it as <yourappname>.entitlements)

<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE plist PUBIC "-//Apple//DTD PLIST" 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>apple.developer.ubiquity-container-identifiers</key>

<array>
<string>$(TeamIdentifierPrefix).com.yourdomain.icloudapp</string>
</array>

<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$($(TeamIdentifierPrefix).com.yourdomain.icloudapp)</string>

</dict>
</plist>

After saving you file simply drag and drop it to your app on xcode.

written by: infinitywebseo 

Monday, 24 June 2013

UIDocument does not allow you to write strings directly to disk

If you are using UIDocument in your app, always remember that UIDocument doesn't allow you to write strings directly to disk.

You need to package the string value in NSData then you can write it to disk. You can do it using the contentsForType:error method.

Below is a sample code, first check that the string is not NULL :

- (id)contentsForType:(NSString *)typeName error:(NSError **) myError{
    if (!self.stringDocument)
        self.stringDocument = @"";

    NSData *nsDataDocument = [self.stringDocument
                           dataUsingEncoding:NSUTF8StringEncoding];
    return nsDataDocument;
}

written by: infinitywebseo 

Wednesday, 19 June 2013

How to Check iCloud is available in your app?

After enabling icloud on your app, just copy and paste the highlighted lines of code to your appdelegate.m to check that icloud is available for your app:

- (void)initializeiCloudAccess {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        if ([[NSFileManager defaultManager]
             URLForUbiquityContainerIdentifier:nil] != nil)
            NSLog(@"iCloud is available\n");
        else
            NSLog(@"iCloud is not available.\n");
    });
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   
    [self initializeiCloudAccess];

    return YES;
}

The executable was signed with invalid entitlements. (0xE8008016)


Summary: if you have this error --> Try creating your new provisional profile through xcode > organiser it may solve the problem. (Don't create it trough your developer account on-line)

I had this error when I tried to run an app that uses icloud on an ios device. For icloud application you must create an app id  and new provisional profile.

What I did was that I create my new provisional trough my apple developer account website. Even thought I refreshed my provisional profile on xcode > organiser, I couldn't get rid of the error,  never mind few hours of searching on the web trying to find out the answer which was unsuccessful.


At the end, I just deleted my app id, and provisional profile. Then I create  a new app id, and this time I create my provisional profile through xcode > organiser, run my app again and it just worked.

written by: infinitywebseo 

Wednesday, 12 June 2013

iOS 7 --> Things that you need to change about your app

 
All the contents on this blog are derived from apple developer website, its just a quick short-list for my own personal use.  I hope you find it useful.


Things I must do:
  • Update app icon to 120 x 120 (iOS 7 - Higher Resolution).
  • Update the launch image to include the status bar area.
  • Support Retina display.


Things I should do:  
Prepare for borderless buttons by moving away from supplying button background images and by reassessing your layout.

Use translucent UI Element & Auto-layout.

View controllers should use full screen layout. Don't use "wantsFullScreenLayout", its deprecated in iOS 7. Instead use the following properties:
  • edgeForExtendedLayout
  • extendedLayoutIncludeOpaqueBars
  • automaticalAdjustScrollViewInsets

For custom animated transitions between views click on --> UIViewControllerInteractiveTransitioning Protocol Reference


Using tint color: In iOS 7 tint is a property of UIView. Specify a tint color for entire app using following line: window.tintColor = [UIColor purpleColor]; By default tint color is nil which means that it uses the parent tint color. 
Remember, its best to change tint color when the app is off screen.


Bars and Bar Buttons barPosition in iOS 7 is a property for identifying bar position. The UIBarPositionTopAttached -----> a bar is at the top of the screen and its background extends upward into the status bar area. 
UIBarPositionTop ------> a bar is at the top of its local context—for example, at the top of a popover—and that it doesn’t provide a background for the status bar. 


Status Bar iOS 7
In iOS 7 You can control the style of the status bar from an individual view controller and change it while the app runs. In order to do it, add the UIViewControllerBasedStatusAppearance key to an app's Info.plist file and give it the value YES.


Navigation Bar iOS 7
Bar Style: by default the translucent property is YES.
Appearance: A one-pixel hairline appears a the button edge.  
Tinting: Use tintColor to tint bar button items.
             Use barTintColor to tint the bar background.


Collection View iOS 7
Collection view supports animated transitions between layouts. Click to read the documentation ------> UICollectionViewTransitionLayout Class Reference

Image View iOS 7
UI Image contains tintColor property and when image uses UIImageRenderingModeAlwaysTemplate mode, tintColor is applied to the image.

Map View iOS 7
In iOS 7 there is a new class called MKOverlayRenderer which you can use to create overlay on the top of map view.


Page View Controller iOS 7
To specify orientation use the following methods:
  • pageViewControllerPreferredInterfaceOrientationForPresentation
  • pageViewControllerSupportedInterfaceOrientations 
Scrol View in iOS 7  
automaticallyAdjustsScrollViewInsets ----> to manage scroll view insets.

written by: infinitywebseo 

 

 


Debt Collection

Debt Collectors

iOS 7 Beta a Quick Overview

iOS 7 Beta has so many bugs but the idea is great, its basically amazing. Can't wait for the final version.




written by: infinitywebseo