Thursday 9 October 2014

Making ad hoc build from command line without signing to developer account in Xcode 6 and iOS 8

It was the first problem I face during the use of xcode 6 first time, how can i share .ipa to my clients for demo purpose? I was unable to share an .ipa without signing Apple developer account. Xcode 6 was asking to sign with Developer account to export an .ipa file. Although I had the developer account details but it was the challenge how to make a adhoc build  without signing developer account.
After lots of Googling and consulting with other friends, I found  an alternate solution to achieve ad-hoc  build without signing developer account, solution is  command line/Terminal, you can create a adhoc build using command line tool and or a terminal on mac system.

Let me share the simplest way to create adhoc build using command line tool.

I note down 3 things to create quickest Xcode 6 build. So get ready for these 3 things before opening Terminal.

1- Project path: it will be required in terminal command as a parameter.

2- scheme name: it will be required in terminal command as a parameter.

3- Provisioning Profile name: it will be required in terminal command as a parameter.

Finding scheme name: Default scheme name is the project name but once verify. scheme name displays next to RUN icon in Xcode that is used to execute the app.

Finding Provisioning Profile name: This parameter value will be exact same as it display in Xcode; Provisioning Profile list under Code Signing Identity in build settings section of Xcode 6.

There are three steps two create build from command line tool

1- Clean project
2- Make Archive
3- Export to .ipa file

 Lets start with first. To clean project we will execute below command in Terminal  and or command line tool of mac system.
xcodebuild clean -project <projectname.xcodeproj> -configuration Release -alltargets

here  <projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 

For example on my system's terminal
ajsharma$
xcodebuild clean -project /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -configuration Release -alltargets

Terminal will show you some process and updates and show you success message regarding project clean.
Lets go for next step to Make an archive using below command

xcodebuild archive -project <projectname.xcodeproj> -scheme <schemename> -archivePath <projectname.xcarchive>

here
<projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension


For example on my system's terminal
ajsharma$
xcodebuild archive -project  /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -scheme testApp -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive

I used same path for as project Path for archivePath you may change it. So an archive file will be create at same path as project path.

@workspace:
Sorry I forgot to mention important command for those who have configured their projects under a WorkSpace or using pods in their projects.
For those people there would be slightly change in  command to make an archive. But I was not using workspace.

xcodebuild -workspace <projectname.xcworkspace> -scheme <schemename> archive -archivePath <projectname.xcarchive

 here;
<projectname.xcworkspace > will be replace with the project path with .xcworkspace extension.
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension

Lets go for  final step to Export to .ipa  using below command

xcodebuild -exportArchive -archivePath <projectname.xcarchive> -exportPath <projectname> -exportFormat ipa -exportProvisioningProfile “Provisioning Profile Name”

here
<projectname.xcarchive> will be replace with the project path with .xcarchive extension
<projectname>  will be replace with the project path with out .xcarchive or .xcodeproj extension
“Provisioning Profile Name”  will be replace with the Provisioning Profile Name  as I discussed above.

For example on my system's terminal
ajsharma$
xcodebuild -exportArchive -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive -exportPath /Users/ajsharma/Documents/iPad/testApp/testApp -exportFormat ipa -exportProvisioningProfile TestProvision

If everything works fine the final result screen would be some thing like below text as per my project path.

Moving exported product to '/Users/ajsharma/Documents/iPad/testApp/testApp.ipa'
** EXPORT SUCCEEDED **


You can get the .ipa file from the above path as per your project path at your system and share with your client.

If you have any other best way to create adhoc build without using developer account, please share your comments.


Wednesday 8 October 2014

2 steps to use UITableViewCell separatorinset in ios 8 and setLayoutMargins in iOS 8

During porting from iOS 7.x objective-C based code in to iOS 8.x objective-C, I noticed that UITableviewCell separator disturbed from left and right side. Separator line got margin from left and right. It was fixed in iOS 7.x code using separator "inset" to 0. but it become default 15 in iOS 8 storyboard. even setting it  to zero (0) it didn't worked.

Actually in iOS 8 layoutMargins a new property is introduced. So problem comes in mind;  How to use layoutMargins on the cells and tableview in iOS 8?
it is missing in earlier version. so we need to put a check also to its availability.


Two fix it in iOS 8.x, need to use below 2 steps

1- For Cell

-(void)tableView:(UITableView *)tableView willDisplayCell:
(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

2- For Tableview

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) 
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) 
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

Both steps need to be follow to achieve Separatorinset in iOS 8


This is the best way to use UITableViewCell separatorinset in ios 8 and  setLayoutMargins in iOS 8.

If you have some better way please share your valuable ideas in comment section.



Monday 6 October 2014

How to change UISegmentedControl text font and color

UISegmentedControl is mainly used to toggle between two screen or functionality from a common screen. but some times it requires to change the font size of the UISegmentedControl text. Interface builder is not providing the option to change the text font size.

Let me share the way how to change UISegmentedControl text font size and text color.

Create a new viewcontroller in your project or may create a new project if you dont want to modify your existing project for safety point of view.

I am creating UIsegmented control using code but if you using IBOutlet you can go with that also.

in .h file

@interface ViewController : UIViewController

@property (strong, nonatomic)  UISegmentedControl *segment1;

@property (strong, nonatomic)  UISegmentedControl *segment2;
@end

in .m file

 - (void)viewDidLoad
{
    [super viewDidLoad];
   
     NSMutableArray *segtitleArr=[[NSMutableArray alloc]initWithObjects:@"First1",@"Second2", nil];
    _segment1 = [[UISegmentedControl alloc]initWithItems:segtitleArr];
    _segment1.frame = CGRectMake(30, 50, 252, 29);
   
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIFont fontWithName:@"Helvetica" size:17], NSFontAttributeName,
                                [UIColor redColor], NSForegroundColorAttributeName, nil];

  
    [_segment setTitleTextAttributes:attributes forState:UIControlStateNormal];
  
    [self.view addSubview:_segment];



//creating second segment.
  
    NSMutableArray *segtitleArr2=[[NSMutableArray alloc]initWithObjects:@"Third3",@"Fourth"4, nil];
    _segment2 = [[UISegmentedControl alloc]initWithItems:segtitleArr2];
    _segment2.frame = CGRectMake(30, 152, 252, 29);
    _segment2.tintColor = [UIColor colorWithRed: 8/255.0 green:83/255.0 blue:131/255.0 alpha:1.0];
  
    NSDictionary *attributes2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIFont fontWithName:@"Helvetica" size:10], NSFontAttributeName,
                                [UIColor orangeColor], NSForegroundColorAttributeName, nil];

  
    [_segment2 setTitleTextAttributes:attributes2 forState:UIControlStateNormal];
  
    [self.view addSubview:_segment2];




Best way to change UISegmentedControl text colr and  size



Above code will show you two segment control in different text size and font color and selected segmented color change using tint color property.
In both UISegmented control one thing is common that is a NSDictionary having objects of Font/Text and color these you can change as per your requirement.

If you find another best way to change UISegmentedControl  text  size and color, Please share using your comments below.

 

  
}

Friday 3 October 2014

DataCalculation: How to use User Defined Runtime Attributes in Xcod...

DataCalculation: How to use User Defined Runtime Attributes in Xcod...: What is the mean by “User Defined Runtime Attributes” ? “User Defined Runtime Attributes” are featured from Xcode 4 and iOS 5,  great fea...

How to use User Defined Runtime Attributes in Xcode Interface Builder

What is the mean by “User Defined Runtime Attributes” ?

“User Defined Runtime Attributes” are featured from Xcode 4 and iOS 5,  great feature supported in interface builder. But bad thing is that most of the intermediate developers are not aware about it.

Where can I found in Interface builder ?
take a look under Identity Inspector tab.


User Defined Runtime Atrributes screen in interface builder




Key Path- Its like properties of controls and or setter methods.
Value- Assigned values to those properties and or setter methods.
What about the 'Type' ?

Below are the supported Attributes types 


User Defined Runtime Atrributes Supported types

    

Lets come to the point.

How can we  use these in our application.
It is not possible to set a View's CornerRadius or borderWidth using interface builder's Attributes Inspector. To achieve this we unnecessarily creates a IBOutlet and use CALayer for this.

like

    _myBGview.layer.borderWidth = 3;
    _myBGviewlayer.cornerRadius = 15;


Lets do the same using Interface builder

Configure User Defined Runtime attributes in interface builder


Wow its so simple Just fill out the objects property and select type and set the value

One problem is here that I required to set the color of the border but CALayer's color is CGColorRef type not UIColor type

So we can use a trick of Objective-C's Category. Just implement a setter method.

@implementation CALayer (Enhancement)

-(void)setMycolorFromcolor:(UIColor*)mycolor
{
     self.borderColor = mycolor.CGColor;
}




Configure User Defined Runtime attributes of unsupported types in interface builder





 Its all about Using User Defined Runtime Attributes from my side. If  you have any other best way to configure User Defined Runtime Attributes in Interface builder
 Please share using comments section.
It would be much appreciated.