Showing posts with label iOS7. Show all posts
Showing posts with label iOS7. Show all posts

Monday, 13 January 2014

iOS 7 Layout changes | XCode5

Hey Folks,
Here some fixes/changes on iOS7:

1) UINavigationBar Background Image :
 if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")
    [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar_bg_ios7.png"]forBarMetrics:UIBarMetricsDefault];
else
    [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"]forBarMetrics:UIBarMetricsDefault];

Important :Image should be of 320px x 64px (if you want to support lower versions, then you have to add another image of 320px x 44px)

2) UINavigationBar title color : (By default Black color in iOS7)
[[UINavigationBar appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor];forKey:UITextAttributeTextColor]];

3) UIBarButtonItem title color : (By default Blue color in iOS7)
[[UIBarButtonItem appearance]setTintColor:[UIColor whiteColor]];


4) UISearchBar Style + Cancel barButtonItem color :
[self.searchBar setSearchBarStyle:UISearchBarStyleMinimal];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class,nil]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:kBlueTintColor,UITextAttributeTextColor,[NSValue valueWithUIOffset:UIOffsetMake(0,1)],UITextAttributeTextShadowOffset,nil]forState:UIControlStateNormal];

5) APPDelegate Window
 self.window.tintColor = [UIColor whiteColor]; 

Important: Beware to use this code. Every UI elements traits behaves as in white color(i.e UIbarbutton item, keyboard focus etc..)

6) UITextView | UITextField focus color
[[UITextView appearance] setTintColor:kBlueTintColor]

Friday, 27 September 2013

Add Subviews inside UIAlertview in iOS7

Constants
#import "CustomIOS7AlertView.h"
#define alertTag 2
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

Please find CustomIOS7AlertView .h and .m file Click here to download
Code for Custom UIAlertview subviews in iOS7 
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
   CustomIOS7AlertView *alert = [[CustomIOS7AlertView alloc] init];
   alert.backgroundColor = [UIColor whiteColor];
   [alert setContainerView:[self createAlertView:@"Check for iOS7 UIAlertview"]];
   [alert setButtonTitles:[NSMutableArray arrayWithObjects:@"Okay",@"Cancel",nil]];
   [alert setDelegate:self];
   alert.tag = alertTag;
   [alert show];
   [self.view addSubview:alert];
}else{
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg message:@"" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Cancel",nil];
   alert.tag = alertTag;
   [alert show];
}
- (UIView *)createAlertView:(NSString *)msg{
    UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
    demoView.layer.cornerRadius = 8.0f;
    demoView.layer.masksToBounds = YES;
    demoView.backgroundColor = [UIColor whiteColor];
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 280, 30)];
    title.text = msg;
    title.textColor = [UIColor blackColor];
    title.backgroundColor = [UIColor clearColor];
    title.font =  [UIFont fontWithName:@"verdana" size:14];
    title.numberOfLines = 0;
    [demoView addSubview:title];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame= CGRectMake(20,50,38,30);
    [btn setImage:[UIImage imageNamed:@"circle-checked.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(toggleMe:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor clearColor];
    [demoView  addSubview:btn];
    UILabel *lblShare= [[UILabel alloc] initWithFrame:CGRectMake(70, 50, 190, 30)];
    lblShare.text=@"share on facebook";
    lblShare.numberOfLines=1;
    lblShare.textColor =[UIColor blackColor];
    lblShare.font=[UIFont fontWithName:@"verdana" size:14];
    lblShare.textAlignment=UITextAlignmentLeft;
    lblShare.backgroundColor =[UIColor clearColor];
    [demoView addSubview:lblShare];
    return demoView;
}
//Delegate
- (void)customIOS7dialogButtonTouchUpInside:(CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{
 NSLog(@"Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
 NSInteger tag = alertView.tag;
 if (tag == alertTag){
 if (buttonIndex == 0)
 NSLog(@"pressed okay");
 else
 NSLog(@"pressed cancel");
 }
[alertView close];
}
// Button target
- (IBAction) toggleMe : (id) sender{
 UIButton *btn =  (UIButton *) sender;
 [btn setImage:[UIImage imageNamed:@"circle-unchecked.png"] forState:UIControlStateNormal];
}
//Output