Wednesday, March 29, 2017

Using Custom Fonts in Swift 3.0

Using Custom Fonts in Swift Code

 We could set the custom font in code.

To use a custom font we need to refer to it by name. But the name often isn’t the same as the font’s file name. There are 2 ways to find the name:
  1. Install the font on your Mac. Open Font Book, open the font and see what name is listed.
  2. Programmatically list the available fonts in your app.

    means follow below step,
    1.include the fonts in your project
    2. include the fonts in build phase,
    3. include install the font.
    4. RESTART the xcode
    5. and finally, choose your custom font, make sure to make it plain and not attributed. Select "CUSTOM" to find the custom font and not "SYSTEM".

Include your iOS custom fonts in your application Plist
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.



Find the name of the font
// MARK: - UIFont Extension

extension UIFont {
    func Light(_ size: CGFloat) -> UIFont {
        return UIFont(name: "Roboto-Light", size: getSize(size))!
    }
    func Regular(_ size: CGFloat) -> UIFont {
        return UIFont(name: "Roboto-Regular", size: getSize(size))!
    }
    func Medium(_ size: CGFloat) -> UIFont {
        return UIFont(name: "Roboto-Medium", size: getSize(size))!
    }
    func Bold(_ size: CGFloat) -> UIFont {
        return UIFont(name: "Roboto-Bold", size: getSize(size))!
    }
    func getSize (_ size: CGFloat) -> CGFloat {
        var sizeMain = size
        if Screen.isIphone6Plus {
            sizeMain = sizeMain + 2
        }
        else if Screen.isIphone6 {
            sizeMain = sizeMain + 1
        }
        return CGFloat(sizeMain)
    }
}

Below is the use of category.
        lblTitle.font = UIFont().Regular(16)
        lblPrice.font = UIFont().Medium(13)
        btnPrice.titleLabel!.font = UIFont().Medium(13)
        lblAuthorName.font = UIFont().Regular(12)
        lblSizeNote.font = UIFont().Regular(12)
        lblAuthorNameStatic.font = UIFont().Medium(13)
        lblSizeNoteStatic. font = UIFont (). Medium (13)
Enjoy

Thursday, July 14, 2016

New features of iOS 10.0

The latest IOS version incorporates many new features and upgrades. Through this post, we bring to you the four astonishing features of iOS 10.
Raise To Wake
Raise to wake is by far the most exciting feature offered by iOS 10 which brings the engrossing functionality of Apple Smart Watch to the iPhone and iPad. This enthralling feature lights up your iPhone whenever you lift it up and takes you directly to the home screen. The feature was first introduced in Apple Smart Watch before being a part of the iOS ecosystem.
However, this specific feature is only compatible with iPhone SE, iPhone 6s, iPhone 6s Plus and all the latest versions that are yet to come.
Siri Upgrade
You can now activate your Siri for all the non-Apple apps as well. The Siri is based on the prevalent voice control functionality. It’s just that now you’ll be able to use it with almost any app installed in your iPhone.
For instance, you can give direct commands to Siri like, “Send a Whatsapp message to Patrick” or “Skype Andrea that I’m on my way.” You can now even ask Siri to solve mathematical problems for you. For instance, “What is 7+1?” or “What is the square root of 256?”
Face Sorting (Photos)
Face Sorting is yet another enthralling feature of iOS 10 which scrutinizes the facial expressions of a person from your saved photos and then sorts and imports all the photos of that person to a specific folder. All these folders are called Smart Albums and somewhat around 11 billion calculations are performed for each photo to create a smart album. All this has been possible by the inception of the finest form of artificial intelligence.
QuickType
QuickType is another engrossing feature that brings the intelligence of Siri to the keyboard. QuickType functionality provides intelligent suggestions to the users while they’re typing. QuickType basically uses, contact cues to predict what you’re going to write next. It also helps you save a lot of time that you usually take in typing a particular message. For instance, if someone ask you about your location, then it’ll automatically offer you to share your current location and you can share the location in a single tap.
SMARTER LOCK SCREEN
Apple has improved the lock screen experience with iOS 10. You'll now be able view your lock screen just by picking up your phone, as well as action notifications using 3D Touch. These features aren't quite as revolutionary as Apple is making out, but it's good they're finally landing on iDevices.
3D TOUCH & WIDGETS
Talking of 3D Touch, Apple is filling out the usage of its big hardware addition of last year's iPhone 6S. You'll be able to press and hold firmly on app icons to bring up widgets - essentially providing you with key information without actually entering the apps.


MAPS
Maps, like Siri and Photos, are getting smarter and more open. Developers will be able to access the Maps API in iOS 10 and beyond, so we can look forward to things like native restaurant booking and ride hailing.
There's some aesthetic tweaks, too, but more meaningfully there's loads more predictive functionality – things like nearby dining suggestions. There's also improved navigation, including traffic report integration, so Maps will now be able to offer you alternative routes when there's loads of congestion – all of which is coming to Car Play too.
As with many other areas of iOS 10, Apple is integrating third party services into Maps. You'll be able to make dinner reservations with restaurants from directly within the Maps app, for example.
HOME
IOS will feature an all new native app called Home. Expanding on the HomeKit framework, it'll be one-stop shop for all your connected and smart home gear. It'll also feature in the Control Center, so you can access it from the lock screen.

MESSAGES
In iOS 10, Messages are getting a pretty substantial overhaul. You'll be able to write messages in your own handwriting, alter the way message bubbles look, send quick 'Tapback' responses, and even add animations.
Emoji are getting bigger (three times bigger) and easier to insert, with iOS recommending potential word replacements for you. Meanwhile, you'll be able to slap virtual stickers all over your message threads.
But potentially the biggest addition of all will be iMessage apps. Apple is essentially turning the app in its own platform, with third party developers able to make their content accessible directly through the Messages app.

APPLE MUSIC
We knew this one was coming, but it was good to see confirmation that Apple is going back to the drawing board with Apple Music nonetheless.
Apple Music's new approach looks a lot cleaner and simpler than before. Upon entering the app, for example, you'll be taken straight to the Library section.
You'll also be able to view lyrics while you're listening to your music. Well, someone must have asked for it...

Tuesday, December 30, 2014

Login With Facebook Usinf Facebook SDK & Get Data of User


Configure .Plist File

In .Plist File
Add FacebookAppID
Eg. open Info.plist file 

Add new Row & Add like this.
FacebookAppID : string :  1376543139268660









This FacebookAppID Number
 you can get from 
Registering your Application From Facebook API.

For More Info Click here

Follow step given in Facebook link & you can get Facebook App ID & Set it in .PList File.



Download Facebook SDK & Import it.

in ViewController .h file
Add below Code.

#import <FacebookSDK/FacebookSDK.h>

@property (weak, nonatomic) IBOutlet UIButton *btnFacebook;
- (IBAction)btnFacebook:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *profilePictureView;

// In your view header file:
@property (weak, nonatomic) IBOutlet FBLoginView *loginView;
@property (retain, nonatomic) IBOutlet UIWebView *tempWebView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

in ViewController .m file
Set Delegate in ViewController Like this.
@interface LoginViewController ()<FBLoginViewDelegate>

@synthesize btnFacebook,profilePictureView,tempWebView;

- (IBAction)btnFacebook:(id)sender {
        NSLog(@"BTN_Facebook");
        
        //set Read Permissions to Facebook SDK
        FBLoginView *loginView =
        [[FBLoginView alloc] initWithReadPermissions:
         @[@"public_profile", @"email", @"user_friends"]];
        loginView.delegate = self;
        
        //set frame
        loginView.frame = CGRectMake(30, 226, 260, 53);
        for (id obj in self.loginView.subviews)
        {
            if ([obj isKindOfClass:[UIButton class]])
            { 
                //Create Custom Login Button USing ByDefault Image of Facebook given in SDK
                UIButton * loginButton =  obj;
                UIImage *loginImage = [UIImage imageNamed:@"signfacebook.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
                [loginButton setTitle:nil forState:UIControlStateSelected];
                [loginButton setTitle:nil forState:UIControlStateHighlighted];
                [loginButton sizeToFit];
            }
            if ([obj isKindOfClass:[UILabel class]])
            {
                UILabel * loginLabel =  obj;
                loginLabel.text = @"";
                loginLabel.textAlignment = NSTextAlignmentCenter;
                loginLabel.frame = CGRectMake(0, 0, 271, 37);
                [loginLabel removeFromSuperview];
            }
        }
        loginView.delegate = self;

        //Add in View
        [self.view addSubview:loginView];
        ///
    }

Then After Set Delegate method of Facebook SDK FBLoginView

// This method will be called when the user information has been fetched
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user
{
    NSLog(@"facebook user Id %@",user.id);
    NSLog(@"facebook name=%@",user.name);
    NSLog(@"facebook email=%@",[user objectForKey:@"email"]);
    NSLog(@"facebook first_name=%@",[user objectForKey:@"first_name"]);
    NSLog(@"facebook last_name=%@",[user objectForKey:@"last_name"]);
    NSLog(@"facebook id=%@",[user objectForKey:@"id"]);
    
    // to get profile picture add this code
    
    
    //for image scale use type -> {square,small,normal,large}
    NSString *str=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=normal",[user objectForKey:@"id"]];
    NSLog(@"str= %@",str);
    
    //download image from url
    UIImage *img=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]];
    
    //set image to Imageview
    self.profilePictureView.image=img;
}
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
{

}
// Logged-out user experience
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
{
    NSLog(@"You're not logged in!");
}
// Handle possible errors that can occur during login

- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
{
    // no action can be done on facebook if there is no session on open state
    if (!FBSession.activeSession.isOpen)
    {//[@"public_profile", @"email", @"user_friends"
        FBSession *session = [[FBSession alloc] initWithPermissions:@[@"publish_stream",@"email",@"user_photos"]];
        [FBSession setActiveSession:session];
        
        // Here this behavior garantees that the iOS Login Dialog is not shown, because it was causing some login issues
        // The fallback flow will be: 1- Facebook App Native Login Dialog; 2- Facebook App Web Login Dialog; 3- Mobile Safari Login Dialog
        [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView
                                  completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
         {
             
             if(error)
                 
             { // your code here
                 
                 NSString *alertMessage, *alertTitle;
                 
                 // If the user should perform an action outside of you app to recover,
                 // the SDK will provide a message for the user, you just need to surface it.
                 // This conveniently handles cases like Facebook password change or unverified Facebook accounts.
                 if ([FBErrorUtility shouldNotifyUserForError:error]) {
                     alertTitle = @"Facebook error";
                     alertMessage = [FBErrorUtility userMessageForError:error];
                     
                     // This code will handle session closures that happen outside of the app
                     // You can take a look at our error handling guide to know more about it
                     // https://developers.facebook.com/docs/ios/errors
                 } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession) {
                     alertTitle = @"Session Error";
                     alertMessage = @"Your current session is no longer valid. Please log in again.";
                     
                     // If the user has cancelled a login, we will do nothing.
                     // You can also choose to show the user a message if cancelling login will result in
                     // the user not being able to complete a task they had initiated in your app
                     // (like accessing FB-stored information or posting to Facebook)
                 } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
                     NSLog(@"user cancelled login");
                     
                     // For simplicity, this sample handles other errors with a generic message
                     // You can checkout our error handling guide for more detailed information
                     // https://developers.facebook.com/docs/ios/errors
                 } else {
                     alertTitle  = @"Something went wrong";
                     alertMessage = @"Please try again later.";
                     NSLog(@"Unexpected error:%@", error);
                 }
                 
                 if (alertMessage) {
                     [[[UIAlertView alloc] initWithTitle:alertTitle
                                                 message:alertMessage
                                                delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil] show];
                 }
                 
                 
             }
             else
             { // your code here
                 
                 NSLog(@"no error in Login with Facebook..");
             }
             
         }];
    }
    //////-------------------
}