Skip to main content

Give Parse.com dialogs a modern look

I’ve been playing around with Parse.com, which is an excellent “mobile backend” framework.  It gives you an easy way to use database, user management, and some UI to get you started on all the major mobile devices.  As with all the frameworks that do a lot, it gets tricky when you need things to look or act differently than what you get “out of the box.”  I am going to share some customizations I have made to introduce a flat UI look (Fig 1) instead of the dark brushed metal look (Fig 2).


1. Before we begin,  follow the iOS guide to get the basic setup: https://parse.com/docs/ios_guide .
2. In order to do major customizations the UI for Login or Signup dialog you need to subclass the standard Parse.com classes.  Parse.com has a tutorial on how to do that here: https://parse.com/tutorials/login-and-signup-views .
3. If your app requires login in the viewDidLoad method of the first view you will need to see if there is an active user and display the login dialog if there isn’t.  An interesting fact about Parse is that it will keep the session between app launches which is very nice.  In the code below you can see that I am instantiating both the GCLoginViewController and the GCSignUpViewController.  They are both subclasses of the Parse framework classes.
    if( ! [PFUser currentUser]) {
        logInViewController = [[GCLoginViewController alloc] init];
        [logInViewController setDelegate:self];
        logInViewController.fields = PFLogInFieldsUsernameAndPassword
                                    | PFLogInFieldsLogInButton
                                    | PFLogInFieldsSignUpButton
                                    | PFLogInFieldsPasswordForgotten
                                    | PFLogInFieldsFacebook;
        
        GCSignUpViewController* signUpViewController = [[GCSignUpViewController alloc] init];
        [signUpViewController setDelegate:self];
        [logInViewController setSignUpController:signUpViewController];
        
        
        [self presentViewController:logInViewController animated:YES completion:nil];
    }
4. The real styling is happening in the viewDidLoad function of the subclasses.  Here is my GCLoginViewController method.  You can see that button styling happens often enough that I actually created a class to style buttons with images and buttons without images.

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.logInView setLogo:[[UIImageView alloc] 
initWithImage:[UIImage imageNamed:@"MainIcon-small"]]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    // Remove text shadow
    CALayer *layer = self.logInView.usernameField.layer;
    layer.shadowOpacity = 0.0f;
    layer = self.logInView.passwordField.layer;
    layer.shadowOpacity = 0.0f;
    layer = self.logInView.externalLogInLabel.layer;
    layer.shadowOpacity = 0.0f;
    layer = self.logInView.signUpLabel.layer;
    layer.shadowOpacity = 0.0f;
    
    [self.logInView.usernameField setTextColor:[UIColor blackColor]];
    [self.logInView.passwordField setTextColor:[UIColor blackColor]];
    [self.logInView.externalLogInLabel setTextColor:[UIColor blackColor]];
    [self.logInView.signUpLabel setTextColor:[UIColor blackColor]];
    
    // login button
    UIColor* gold = [UIColor colorWithRed:177.0f/255.0f green:117.0f/255.0f blue:0.0f alpha:1.0f];
    UIColor* facebookBlue = [UIColor colorWithRed:59.0f/255.0f green:89.0f/255.0f blue:152.0f/255.0f alpha:1.0f];

    [GCButtonStyles colorButton:self.logInView.logInButton 
background:gold textColor:[UIColor whiteColor]];
    [GCButtonStyles colorButton:self.logInView.facebookButton 
background:facebookBlue textColor:[UIColor whiteColor]];
    [GCButtonStyles colorButton:self.logInView.signUpButton 
background:[UIColor lightGrayColor] textColor:[UIColor whiteColor]];
    [GCButtonStyles colorButton:self.logInView.passwordForgottenButton 
background:[UIColor lightGrayColor] textColor:[UIColor whiteColor]];
    [GCButtonStyles colorButtonWithImage:self.logInView.passwordForgottenButton 
background:[UIColor lightGrayColor] textColor:[UIColor whiteColor]
      image:[UIImage imageNamed:@"forgot-image"]];
}

5. The GCSignUpViewController is using the same functions

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [super viewDidLoad];
    [self.signUpView setLogo:[[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"MainIcon-small"]]];
    self.view.backgroundColor = [UIColor whiteColor];
 
    // Remove text shadow
    CALayer *layer = self.signUpView.usernameField.layer;
    layer.shadowOpacity = 0.0f;
    layer = self.signUpView.passwordField.layer;
    layer.shadowOpacity = 0.0f;
    layer = self.signUpView.emailField .layer;
    layer.shadowOpacity = 0.0f;
 
    [self.signUpView.usernameField setTextColor:[UIColor blackColor]];
    [self.signUpView.passwordField setTextColor:[UIColor blackColor]];
    [self.signUpView.emailField setTextColor:[UIColor blackColor]];

    // login button
    UIColor* gold = [UIColor colorWithRed:177.0f/255.0f green:117.0f/255.0f blue:0.0f alpha:1.0f];
 
    [GCButtonStyles colorButton:self.signUpView.signUpButton background:gold
textColor:[UIColor whiteColor]];
}

6. The actual styling functions have a bunch of code because Apple exposes a bunch of elements that you can customize.  Parse puts the background and foreground images and colors so in order to completely reset the styles I am setting all those properties.
@interface GCButtonStyles : NSObject
+(void) colorButton:(UIButton*) button background:(UIColor*)
background textColor:(UIColor*) textColor;
+(void) colorButtonWithImage:(UIButton*) button background:(UIColor*)
background textColor:(UIColor*) textColor image:(UIImage*)image;
@end


#import "GCButtonStyles.h"

@implementation GCButtonStyles

+(void) colorButton:(UIButton*) button background:(UIColor*) background textColor:(UIColor*) textColor {
    [button setBackgroundImage:nil forState:UIControlStateNormal];
    [button setBackgroundImage:nil forState:UIControlStateHighlighted];
    [button setBackgroundImage:nil forState:UIControlStateSelected];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    [button setTitleColor:textColor forState:UIControlStateHighlighted];
    [button setTitleColor:textColor forState:UIControlStateSelected];
    [button setTitleShadowColor:
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f] forState:UIControlStateNormal];
    [button setTitleShadowColor:
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f] forState:UIControlStateSelected];
    [button setBackgroundColor:background];
}

+(void) colorButtonWithImage:(UIButton*) button background:(UIColor*) background textColor:(UIColor*) textColor image:(UIImage*)image
{
    [self colorButton:button background:background textColor:textColor];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:image forState:UIControlStateHighlighted];
    [button setImage:image forState:UIControlStateSelected];
}


@end

These functions can be used on almost any buttons that you get in UI elements regardless of whether they came from Parse or another framework.  In this particular situation the resetting of the styles and backgrounds gives the user interface a more modern, flat look.   Enjoy!

PS: If you liked this post you might also like other hands on blog posts like the TestFlight one: http://www.mikebz.com/2014/08/testflight-and-importance-of-private.html or the 4 Page Guide to Core Data: http://www.mikebz.com/2014/06/4-page-guide-to-core-data.html

Post a Comment

Popular posts from this blog

SDET / QA Engineer Interview Checklist

After interviewing and hiring hundreds of engineers over the past 12+  years I have come up with a few checklists.  I wanted to share one of those with you so you could conduct comprehensive interviews of QA Engineers for your team.

I use this checklist when I review incoming resumes and during the interview.  It keeps me from missing areas that ensure a good team and technology fit.  I hope you make good use of them.  If you think there are good questions or topics that I have missed - get in touch with me!


SDE/T or QA Engineer interview checklist from Mike Borozdin
If you like this checklist you might want to check out these posts:
Emotional Intelligence in Software Teams  and Good-bye manual tester, hello crowdsourcing!

Pull Requests and Code Reviews

Software development involves a great deal of collaboration.  One of the most basic blocks of collaboration on a software development team is a code review.  There have been many different ways of doing code reviews over time, some of this has been dictated by the tools available.  Git and online source collaboration tools created a set of best practices that are worthwhile of adopting on any team.

About a month ago I have looked at various articles about how to best create a Pull Request (PR) and do a code review and the attached presentation is the result of this research.  The presentation can help you guide your team and develop a set of collaboration practices that works for your particular situation.

It’s good to start out with why to seek a code review.  Having clarity about your intentions helps you guide the person helping you with code reviews and also to manage your expectations about you can get out of the code review.  The reasons for seeking a code review are generally …

Why you should take the software job in San Francisco (or not).

Silicon Valley is an iconic place for technology.  Many people say this is the place for the “best and the brightest.”. Apple, Google, Facebook, Salesforce, Twitter and other top companies draw a lot of talent form all over the world and the largest chunk of VC capital goes to companies in the Bay Area, so it seems like moving here is a no brainer!

The real situation is actually not that simple, I believe there are three scenarios where it makes sense, but in many cases living in the Bay yields disappointing results.  The cost of living, housing situation, homeless catastrophe make places like San Francisco a lot less appealing to a lot of people.  So in what situations does it make sense to move to SF?

Startup founder raising millions There are many places to be a startup founder, but if you are looking to raise capital the largest pool of VC money is in the Bay Area.  There is an established network, events and conferences which give founders an opportunity to pitch more people th…