Creating UIColor objects from hex values

It’s pretty inconvenient to create UIColor objects while developing apps for the iPhone, as you need to specific separate values for the RGB parts: red, green, blue.
I found a trick online a few weeks ago on how to automatically generate that code, by simply using a mac
#define UIColorFromRGB(rgbValue) [UIColor

colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 

green:((float)((rgbValue & 0xFF00) >> 8))/255.0 

blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

The usage looks something like this:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

if (nil == cell) {

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];

}

cell.textColor = UIColorFromRGB(0x333333);

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

cell.text = @"Testing 1 2 3";

}

How to add Three20 into your project

  • Source: Download the Three20 source.
  • Three20 is compiled as a static library and the easiest way to add it to your project is to use Xcode’s “dependent project” facilities. Here’s how:
  • Clone the Three20 git repository:
    git clone git://github.com/facebook/three20.git
  • Locate the “Three20.xcodeproj” file under “Three20/src”. Drag Three20.xcodeproj and drop it onto the root of your Xcode project’s “Groups and Files” sidebar. A dialog will appear — make sure “Copy items” is unchecked and “Reference Type” is “Relative to Project” before clicking “Add”.
  • Now you need to link the Three20 static library to your project. Click the “Three20.xcodeproj” item that has just been added to the sidebar. Under the “Details” table, you will see a single item: libThree20.a. Check the checkbox on the far right of libThree20.a.

  • Now you need to add Three20 as a dependency of your project, so Xcode compiles it whenever you compile your project. Expand the “Targets” section of the sidebar and double-click your application’s target. Under the “General” tab you will see a “Direct Dependencies” section. Click the “+” button, select “Three20”, and click “Add Target”.

  • Now you need to add the bundle of images and strings to your app. Locate “Three20.bundle” under “Three20/src” and drag and drop it into your project. A dialog will appear — make sure “Create Folder References” is selected, “Copy items” is unchecked, and “Reference Type” is “Relative to Project” before clicking “Add”.

  • Now you need to add the Core Animation framework to your project. Right click on the “Frameworks” group in your project (or equivalent) and select Add > Existing Frameworks. Then locate QuartzCore.framework and add it to the project.
  • Finally, we need to tell your project where to find the Three20 headers. Open your “Project Settings” and go to the “Build” tab. Be sure to select the appropriate active configuration (eg, Release vs. Debug — eventually you’ll need to change both). Look for “Header Search Paths” and double-click it. Add the relative path from your project’s directory to the “Three20/src” directory. If your project and the Three20 source are in the same parent, you would enter “../Three20/src”.
  • While you are in Project Settings, go to “Other Linker Flags” under the “Linker” section, and add “-ObjC” and “-all_load” to the list of flags.
  • You’re ready to go. Just #import “Three20/Three20.h” anywhere you want to use Three20 classes in your project.

!! Enjoy !!

Use Relative Paths When Adding Frameworks

When you add a framework to your project in Xcode, make sure you use Path Type = “Relative to Current SDK”. There is no option for this when you add the framework. So after the framework has been added to your project, command-click on the framework and select Get Info.

Your paths should look something like this:
System/Library/Frameworks/AudioToolbox.f

rameworkWhy is this important?

When you start developing using both the iPhone simulator and an actual iPhone device you technically switch SDK based on your target. And it’s a real pain to have to adjust all the framework paths each time.

How to change simulator

I just downloaded a project from web and i got following error-

There is no sdk with specified name or path “iPhoneos3.1…”. (you may got error according to your Xcode version)

Here is the solution:

1. Select the main project file in xcode (main sheet which is the name of your project under the groups and files column to the left-top of your project).

2. Then select the info button (blue circled “I” next to build and go).

3. Go to the build panel and under the archetectures section go to the base sdk category and select iphone simulator according to your current Xcode version and close.

4. Close your project window.

5. Reopen the project Build and Go……

!!! Enjoy !!!

Add Button at the footer of UITable

If you want to add more than 1 button in your table footer, just do this:

– (void)viewDidLoad {
[super viewDidLoad];

// Take a UIView and add button in this View

footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
FirstButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[FirstButton setFrame:CGRectMake(20,0,280,40)];
FirstButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];

FirstButton.backgroundColor = [UIColor clearColor];
[FirstButton setTitle:@”First Button” forState:UIControlStateNormal];
[FirstButton addTarget:self action:@selector(FirstButtonClick:)
forControlEvents:UIControlEventTouchUpInside];

[footerView addSubview:FirstButton];

UIButton *SecondButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[SecondButton setFrame:CGRectMake(20, 50, 280, 40)];
SecondButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];

SecondButton.backgroundColor = [UIColor clearColor];
[SecondButton setTitle:@”Second Button” forState:UIControlStateNormal];
[SecondButton addTarget:self action:@selector(SecondButtonClick:) forControlEvents:UIControlEventTouchUpInside];

[footerView addSubview:SecondButton];
}

// In UITableView set Table Footer:

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @”Cell”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

[cell.contentView removeAllSubviews];

[self.tableView setTableFooterView:footerView];

return cell;
}


Deselect Table Row

Just add this code:

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

iPhone OS 4.0: Multitasking, finally :)

The demand for iPhone OS multitasking is nothing new. People have been looking for ways to do more than one thing at once on their iPhones for some time. For example, let’s say you’re chatting on IRC in one application, and you want to hop out to check a Web page. Should you have to disconnect from your IRC session just so you can sneak into Safari? Maybe you want to listen to Pandora radio while shopping at the App Store. Should you have to stop the Pandora music?

People multitask, and now the iPhone OS can too. Starting with the upcoming 4.0 firmware, the iPhone OS will (finally!) allow users to do more than one task at once. As Steve demonstrated today, iPhone OS 4.0 lets you switch tasks by double-clicking the home button. A dock-like bar appears at the bottom of the screen, showing you a list of running applications.

Typically with multitasking, the more processes that you run, the more burden you’ll place on battery life. The application would have to page into and out of memory a lot more, and as a result, less memory and processor power will be available on a per-app basis. It’s a trade-off. For me, and I’m sure for many others, it’s a trade-off we’re willing to make in order to cash in to the associate benefits.

However, it seems that we may not have to fear: Apple says they have found a way around all of these caveats. How, you ask? They are providing background services to applications, allowing the app to stream music, provide notifications, or do other tasks without compromising performance.

What about you? Is this a feature that you’re going to be taking advantage of? Would you rather swap it out for better battery life and app performance? Let us know in the comments.

iPhone OS 4.0: Over 100 new features

Yesterday (Apr 8th 2010) During Apple live event, it was noted that over 100 new features are being added to iPhone OS 4.0. We captured some of that information, and list just a few new features here for your reading pleasure:

  • QuickLook: The feature everyone loves in Mac OS X now comes to iPhone and iPad
  • Folder Storage: You can now have up to 2,160 apps on your iPhone through the use of folders
  • Full app access to still and video data
  • iBooks on iPhone: A smaller version of the iBooks app for the iPhone platform.
  • Unified inbox for Mail: At last, all of your emails go can be viewed in one inbox; no more switching between inboxes. You can also have multiple Exchange accounts. The emails can be organized by threads, much in the same way that they are in Mail.app on the Mac.
  • Wireless App Distribution: Companies that create custom in-house apps no longer need to distribute those through a “wired” connection; employees can now install the apps from anywhere, anytime.
  • Homescreen Wallpaper, Bluetooth Keyboards: The iPhone and iPod touch will get these features that are now on the iPad.
  • Fast app switching
  • Background location: Apps can stay updated with location information even when you switch to another app.
  • Selective use of location: Location can be enabled or disabled on an app-by-app basis.
  • Local notifications: like push notification, but not requiring server access. It’s all done on the phone.
  • Task completion: Items that take some time can now complete in background while other work is going on in foreground. For example, uploading an image to Flickr can happen in background while you’re doing something else.
  • iAds: Developers get 60% of the ad revenue by adding interactive iAds to their apps. You can add fully interactive advertisements without taking people out of your app.
  • Address and Date data detectors: Just like those in Mail.app in Mac OS X, these add information to Address Book and Calendar with a tap.

iPhone 4.0 OS: Now with iAds

Apr 8th 2010

Today at the iPhone 4.0 preview event, Apple announced that one of the new features coming in 4.0 is the iAd network. According to Steve, an average iPhone user is on their phone using apps about half an hour a day. So at one ad every three minutes, that’s 10 ads on each device each day, and with almost ten million devices out there, Apple claims they’ll be serving a billion ad opportunities every day.

And yet this isn’t the huge news about iAds. Here is what makes it a big deal: Apple built the network and is offering it up to developers to use how they’d like, with 60% of the revenue made on those ads going to developers themselves. That’s up a bit from the standard “Apple gets a 30% cut” rule of thumb, but more than half seems more than fair. Apple hosts and sells the ads, and developers take home over half the revenue.

The ad demonstrated live actually looked cool: they showed off little Toy Story 3 ad at the bottom of a news app. Tap the ad, and it comes up with some options (a character list, sounds from each character, etc) and even a game to play, including an option to buy a game from right within the ad. Steve even asked if anyone had seen anything like this before, and among the gathered press, he got silence in response.

Currently, the most educated of guesses is that the AdKit API will be a developer source as well as an iTunes source (iTunes sources are where the App Store and Music Store get their content.)

After the event in the Q&A session, Steve said they attempted to buy AdMob and got sniped by Google, so they bought Quattro and are trying very hard to come up to speed on what web advertising is like, presumably so they can change it. As long as they aren’t trying to get me to refinance my mortgage or whiten my teeth, I’m looking forward to the future of advertising on the iPhone.