Tuesday, 20 November 2012

Show/Hide invisible files in Mac OS

In terminal, type the following:

defaults write com.apple.Finder AppleShowAllFiles YES/NO 
And to unhide Files/Folders:

  sudo chflags nohidden ~/Folder

unhide all subFolder and files:

  sudo chflags -R nohidden ~/Folder

Monday, 12 November 2012

PHP set(display) local time and locale

<?php
//set timezone
$timezone_offset = +8;
$current_time = gmdate('H:i:s', time()+$timezone_offset*60*60);

echo "Current time is $current_time. "

$loc_uk = setlocale(LC_ALL, 'eng');
echo "Preferred locale on this system is $loc_uk";

?>

For supported locale for windows, see here.

Friday, 26 October 2012

Hide keyboard programmatically in iOS

1. Add the following code to the implementation file (.m)

-(void) textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
}

And in the header file (.h)
-(void)textFieldShouldReturn:(UITextField *)textField

2. Add target to the textField:
txtField.delegate = self;
[txtField addTarget:self action:@selector(textFieldShouldReturn:)
          forControlEvents:UIControlEventTouchCancel];

That's it! Test it out. Hope you find this useful. 



Adding Customized Font in iOS Project

1. Download your custom font file, and add it to the Xcode project.

2. In the project.plist file, add a row, type in "Fonts provided by application ", and int the item row,
write your desired name.










3. And don't forget to check the target membership. 

Then you can use it whenever you want by:

textField.font =[UIFont fontWithName:@"HelveticaRoundedLTStd-Bd" size:12];

If you are not sure about the font name, you can open the font file in FontForge and check.

But be warned if you added more than 2 custom fonts from the same family, because iOS does not allow to do that. In that case, you can find a solution here.


Thursday, 6 September 2012

Blackberry 10k Developer Commitment


Blackberry has announced its 10k developer commitment on its official blog. If you publish a blackberry 10 app on the AppWorld and earn at least $1000 USD and not exceeding $10,000 USD, blackberry will pay you the difference between earnings and $10,000 USD for that app.

Sounds great.Maybe I will give it a shot.

The link to the original post:https://developer.blackberry.com/builtforblackberry/commitment/

Check whether a certain app is installed programmatically in Xcode

UIApplication *currentApp = [UIApplication sharedApplication];
   
    if ([currentApp canOpenURL:[NSURL URLWithString:url]]){
        // do something here
}

To open a particular app:
    NSString *appURL = @"appName://";
    [currentApp openUrl:[NSURL URLWithString:appURL]];

Tuesday, 31 July 2012

Titanium: Handling orientation changes on iPhone and iPad



This thing bugs me for a while when I was working on a recent project.
In my project, I need to handle the orientation changes so that I can change the layout and images accordingly. At first, I found a solution in the official Q&A forum, and it works perfectly well on the simulator:

function getOrientation(o) {
switch (o) {
case Titanium.UI.PORTRAIT: {return 'portrait';};break;
case Titanium.UI.UPSIDE_PORTRAIT: {return 'portrait';};break;
case Titanium.UI.LANDSCAPE_LEFT: {return 'landscape';};break;
case Titanium.UI.LANDSCAPE_RIGHT: {return 'landscape';};break;
default: return 'none';
}
}
Ti.Gesture.addEventListener('orientationchange', function(e){
var orientation = e.getOrientation;
if(orientation == "portrait"){
//do something
}else{
//do something else
}

It looks fine. But when I test it on the iPad, something terrible happened. When I tilt the iPad vertically, the UI keeps changing in an unwanted way. That is annoying. So why this happened?
After some searching, I found out that there are actually 6 orientations (x,y,z axis) including face_up and face_down! We need to get rid of those 2 in the orientation change event, so I added another condition before the if statement:

if(orientation == 0 || orientation == 5){
//do nothing
}else if(orientation == "portrait"){
//do something
}else{
//do something else
}

Well of course, that solved the problem!

Customizing Title bar in iOS 5

In iOS 5,customizing title bar with backgroundImage is pretty simple:
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image.png"] forBarMetrics:UIBarMetricsDefault];
But for the text font and color, it requires a little bit more work:      
    [[UINavigationBar appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
    [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
    UITextAttributeTextColor,
    [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
    UITextAttributeTextShadowColor,
    [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
    UITextAttributeTextShadowOffset,
    [UIFont fontWithName:@"STHeitiSC-Medium" size:0.0],
    UITextAttributeFont, nil]];