:: iDavidStudio ::..

Dev log

Archive for the ‘Programming’ Category

iOS 5 Weird Behavior with the UISegmentedControl setDividerImage

without comments

 

I’m using the appearance feature in the iOS 5 to customise the UISegmentedControl. Initially I was using the standard way to define different images for different divider status, it working fine when I tapped on each item. But when I set up the initial selected value to anything that rather than 0 (Zero), the divider behavior very weird:

 

 

 

* Images for different status:

Normal – Normal
Selected – Normal
Normal – Selected

 

 

 

// — Images for divider at different status.

UIImage *imgSelectedUnSelected = [[UIImage imageNamed:@”segments-selected-unselected.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *imgUnSelectedUnSelected = [[UIImage imageNamed:@”segments-unselected-unselected.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *imgUnSelectedSelected = [[UIImage imageNamed:@”segments-unselected-selected.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

// — Dividers
[[UISegmentedControl appearance] setDividerImage:imgSelectedUnSelected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:imgUnSelectedUnSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:imgUnSelectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

 

 

The way to fix this issue, I use a 1 pixel width image for the divider instead of the 3 different images above.

1 pixel divider imag

 

// — Dividers 1pixel images

UIImage *imgSelectedUnSelected = [[UIImage imageNamed:@”segment-divider.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *imgUnSelectedUnSelected = [[UIImage imageNamed:@”segment-divider.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *imgUnSelectedSelected = [[UIImage imageNamed:@”segment-divider.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

 

It works fine now:

 

 

Written by admin

August 12th, 2012 at 6:11 pm

Adding code autoformat feature for your xCode

without comments

If you have been looking for the same codes auto-format feature in the xCode like what you have in the other famous IDE such as Visual Studio.net or Eclipse, you will be disappointed. Unfortunately up to the latest version of the xCode (version 4.4), there aren’t any good auto-format feature built-in. The only one that you might be able to get is the basic code re-indent function.

In this post I will show you how to use the Uncrustify (http://uncrustify.sourceforge.net/) to add auto-format feature into the xCode.

 

STEP 1: We will need to install the Uncrustify on to your mac. The easiest way to install it is through the Homebrew.

* Install the Homebrew: Copy and paste this line of code to your command console:

ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)

 

Next is to install the Uncrustify – just simply copy and paste this command into your command console:

brew install uncrustify

 

SETP 2: You will need to download this Automate workflow file

unzip and then move it to the ~/Library/Services/ folder.  You can go the the folder that you downloaded the Automate workflow file and run the following commands:

mv Uncrustify-Objective-C.workflow.tar.gz ~/Library/Services/ cd ~/Library/Services/ tar zxvf Uncrustify-Objective-C.workflow.tar.gz

 

 

STEP 3: Download the pre set Uncrustify File for the Object-C: Unzip it > Rename it to  .uncrustify_obj_c.cfg  (Please note that there is a dot in front of the file name)and then move it to the ~/ folder by using the below commands:

 mv uncrustify_obj_c.txt ~/.uncrustify_obj_c.cfg

* The format can be customised by modifying the uncrustify_obj_c.txt file before moving to the ~/ folder. Just open the txt file and modify the row that relevant to your style. Each setting has been commented, should be very easy to be customised.

 

STEP 4: Set up the keyboard short cut for autoformat feature.

Go to the “System Preferences – Keyboard – Keyboard Shortcuts – Service” and then look for the newly added services item “Uncrustify Objective-C”. Here is the place that you can add the shorcut for the autoformat feature. Please keep in mind that don’t use any shor cut that might conflict with what xCode already using. The recommended one: “Option + Command + O”, this combination shouldn’t conflict with the xCode pre-set ones.

 

Enjoy it.

Written by admin

August 11th, 2012 at 4:21 pm

How to remove the .svn folders from the Mac OSX

without comments

You might want to clean up your svn info in the projects to resolve the version conflicts with the master copy, in Mac system to clean up the svn folders of your project, you can do the following:

  • Run the Terminal
  • Enter the directory of your project folder (ex: /My_Files/Projects/iBabe/)
  • Type the following commends:
    sudo find ./ -name ".svn" | xargs rm -Rf

Written by admin

June 26th, 2012 at 2:49 pm

Posted in Programming

Reg Exp For Valid Email

without comments

For Javascript

1
var regex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

Written by admin

September 9th, 2011 at 3:27 pm

Posted in Programming

Radio button and checkbox not showing the selected value issue (IE8)

without comments

When trying to print a page that with radio button or checkbox on a IE 8 browser, you will notice that the correct radio button that you had checked did not show on the print. Instead, it is only showing the default one. To fix this issue, here are the javascript that you need:

1
<script type="text/javascript">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// --- For Checkbox
function toggleCheckBox(checkBoxObj) {
    if ( checkBoxObj.getAttribute('checked') != 'checked' ) {
        checkBoxObj.setAttribute('checked','checked');
    }
    else {
        checkBoxObj.removeAttribute("checked");
    }
}
 
// --- For Radio buttons
function toggleRadio(radioBtnObj) {
    var groupName = radioBtnObj.name;
    var checkedId = radioBtnObj.id;
    var groupBtnNodes = document.getradioBtnObjementsByName(groupName);
    for (var i = 0; i < groupBtnNodes.length; i++) {
        if (groupBtnNodes[i].id == checkedId)
            groupBtnNodes[i].setAttribute('checked', 'checked');
        else
            groupBtnNodes[i].removeAttribute('checked');
    }
}
1
</script>
1
2
3
4
5
<!--On the HTML file-->
<input name="chk1" type="checkbox" id="chk1" onclick="toggleCheckBox(this)" />
<input name="chk2" type="checkbox" id="chk2" onclick="toggleCheckBox(this)" />
<input name="r1" type="radio" id="r1" onclick="toggleRadio(this)" />
<input name="r1" type="radio" id="r1" onclick="toggleRadio(this)" />

Written by admin

September 7th, 2011 at 5:32 pm

Posted in Programming