WWDC: Steve Jobs v/s Tim Cook

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

The Wait is over, but the excitement is still there. Yes, Its about the WWDC 2012 and surely its may not be the best of 23 WWDC conferences, but it did not disappoint either. Am sure you can find a lot of info on it here at Engadget WWDC 2012 Live Blog.

 

So, We can never leave the habit of comparing stuff with others, because you the know the value of the product only when you have competition, Right?. So we are going to see in this post certain aspects between this WWDC 2012 and the previous ones run by the Apple’s past Show man – The Steve Jobs.

 

To make it simple, we will focus on following aspects: 

 

1. Secrecy:

 

Tim Cook did mention about doubling down the secrecy @ All Things D Conference, but still Apple could not prevent the features list being spilled out before Today’s WWDC 2012 event.

Here is the question. Did anyone knew about the First iPhone before the WWDC at that time? But on the other hand, Steve jobs was at its best in creating the Pirate teams, except in case of iPhone 4 leak in a bar. 

 

Having said that, the media right now has grown HUGE (with the arrival of Twitter and establishment of Facbeook) than what it was in 2007 and add to the fact that there is immense spotlight on what Apple is doing virtually each day. With that, we should say Tim Cook & Co. did a good job

 

2. Presentation:

 

Tactically, it looks like Tim Cook did not want to come up with his own style and make the show a huge disappointment, Instead he picked the best of the steve jobs slides and wrapped up in a neat show.

 

Check out this slide.

 Screen Shot 2012 06 11 at 10 04 11 PM

 

Add to that the opening of the Keynote with Siri. Starting the Keynote with the a Product or an Ad is not new. The Famous 1984 Keynote ( http://youtu.be/RcRQWGFJ5YY?t=3m8s ) where Steve jobs led Macintosh speak for the first time, and then the Famous Ad ( http://youtu.be/w6SXMtmUsX0?t=7s ) where the PC Guy asks developer to go on Off for a year, are few examples of its kind. 

 

But, If everyone else can copy Apple, then it is absolutely fine for Apple to copy Apple. What do you say?

 

3. WOW Factor

 

You just check back the Keynote video and you see there is that Steve Jobs WOW factor missing. There was some great stuff with retina display, Maps, Next Generation Macbook Pro hardware, and so on.

The WOW factor I am speaking is something like these

 

iPod Nano taken a Smallest Pocket showing its usage. 

 

[youtube=http://youtu.be/7GRv-kv5XEg?t=1m30s]

 

They got a Best Macbook Pro, But there was no sense of excitement created around it. Or Let me say they did not exaggerate it. These are kind of additional things which without its existence may not cause harm on Product sales, but would definitely have a positive effect in its presence.

 

Here’s another piece of Job’s Salesmanship

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

 

Introducing Macbook Air kept within a US Post Envelope showing its thinness:

 

[youtube=http://youtu.be/jDQmvAPYjms?t=2m31s]

 

Comparing all the best in the industry is one of the key aspect of Steve Jobs Keynote. As said earlier, the product value is known only when it has a competition and Apple today missed the key thing to compare Macbook Pro with its Competitiors.

 

Another example, is that they have taken a dig at Window in the past, but this time with the whole new maps, they demonstrated without a word on Google. I wonder if steve could resisted to do that!!

 

But Having said this, there is no harm done as their products introduced today speaks for themselves.

 

4. The Naming:

 

Something has gone wrong with Tim Cook and Co in naming their products. They do the best products but could not come up with best names for it. The ‘The New iPad’ (see the second ‘the’ in my sentence, I hate it) is really awkward. Definitely makes it much more confusing when the next iPad comes out.

 

And the worse is they did not name or did they really name the Macbook Pro as “Macbook Book Pro with Retina Display’ ?

Even worser, they don’t have the name on the Physical Device. Atleast, I don’t see them on the one displayed in Ads.

 

Screen Shot 2012 06 11 at 10 55 01 PMPro name

 

This is such a delicate thing, it acts as an Advertisement and plays a role in word of mouth advertisements for Apple. I always get excited to spot a Apple product in Bollywood and other regional language movies adopted to show the richness of the Character and that moment we feel proud to see the Apple Logo and the name, in case only the display is shown.

 

 

Summary:

 

There are other minute things like the way Tim Cook slowed down his pace than compared to his iPhone 4S keynote, the humors created by Phil Schiller and Scott on Android, and all these things show that the effort is being made to make the Conference a success.

 

To complement Tim Cook, He has made One major improvement from his Previous iPhone 4S event where he did not stay on his statistics for too long.

 

Overall, A decent Job by Tim Cook and Co where they took no risk in experimenting new ideas in Keynote and were pretty happy in demonstrating the tested and successful methods of presentations. Having said, it is hard on them to expect a new stuff in such a short time, and the fact that Steve Jobs Legacy has created a Halo effect in our minds. In that regards, Its a Job Well Done.

 

In Simple words, Their amazing products drove the show for themselves.

 

I wish Tim Cook & Co, and Apple All the very best 🙂

 

 

 

UITableView Tricks

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

 

 

 

 

Recently we came across innovative UI controls like Path and Clear controls. I am pretty amazed to see a simple UITableView and its cells in iOS, can be tweaked to get a eye-catching effects as in Clear app.  After that there came a series of controls using UITableView, but this one from raw engineering was quiet nice.

 

After playing with it, I revisited the nuances of UITableView and came up with this simple UI Layoout which is our topic now. Take at look at this demo

 

[youtube=http://youtu.be/gaM4V9Dcd4k]

 

You can find the Circle View Source in GitHub

 

I drew this sketch quickly.

 

 

IMG 4359

  

 

I laid down some rules before I started implementing.

 

1. I made clear that this control will not built ground up from scratch

2. Want to leverage the full power of Dequeue in UITableView 

3. Above two rules, means I should be concentrating only on how the content is laid out to present the data in different manner to the user and make it fun.

 

The main task that revolves around this control is how do we lay out the table cells. I used some basic trigonometry function which find out the point in circumference of the circle.

 

So the heart of this control resides in this method where on the while we find out the YPosition of each cell and adding yOffset of the Scrollview’s content offset. This means that the cell would move relatively as the tableview is scrolled.

 

The goal is to find out the X Position which is obtained by using Circle / Ellipse Equation

 

y = vertical_radius * sin ( angle )


x = horizontal_radius * cos (angle)

 

-(void)setupShapeFormationInVisibleCells

{

    NSArray *indexpaths = [mTableViewindexPathsForVisibleRows];

    float shift = ((int)mTableView.contentOffset.y % (int)mTableView.rowHeight);  

    int totalVisibleCells =[indexpaths count];

   

    float y = 0.0;

    float radius = mTableView.frame.size.height/2.0f;

    float xRadius = radius;

    

    for( NSUInteger index =0; index < totalVisibleCells; index++ )

    {

        BBCell *cell = (BBCell*)[mTableView cellForRowAtIndexPath:[ indexpaths objectAtIndex:index]];

        CGRect frame = cell.frame;

        //we get the yPoint on the circle of this Cell

        y = (radius-(index*mTableView.rowHeight) );//ideal yPoint if the scroll offset is zero

        y+=shift;//add the scroll offset

        

        

        //We can find the x Point by finding the Angle from the Ellipse Equation of finding y

        //i.e. Y= vertical_radius * sin(t )

        // t= asin(Y / vertical_radius) or asin = sin inverse

        float angle = asinf(y/(radius));

        

        //Apply Angle in X point of Ellipse equation

        //i.e. X = horizontal_radius * cos( t )

        //here horizontal_radius would be some percentage off the vertical radius.

        //percentage is defined by HORIZONTAL_RADIUS_RATIO

        //HORIZONTAL_RADIUS_RATIO of 1 is equal to circle

        float x = (floorf(xRadius*HORIZONTAL_RADIUS_RATIO)) * cosf(angle );

        x = x + HORIZONTAL_TRANSLATION;

        

        frame.origin.x = x ;

        if( !isnan(x))

        {

            cell.frame = frame;

        }

    }

}

 

 

Couple Macros found in source code which you could control”

  • HORIZONTAL_RADIUS_RATIO – defines the ratio between Vertiacl and horizontal radius. HORIZONTAL_RADIUS_RATIO of value 1 is equal to circle
  • HORIZONTAL_TRANSLATION – Helps translate the position of whole Circle / Ellipse i.e the position of the cells 

You can find the Circle View Source in GitHub

 

 

IMPORTANT UPDATE: 

 

A major improvement has been made to this project. Please read UITableView Tricks – Infinite Scrolling  to know about the new features and improvements.

 

 

——————————————————————————————-

UPDATE #1: 

This Post has been featured in 

 

 ——————————————————————————————–

UPDATE #2:

Have modified the source code to support the inverse form of the circle i.e the circle can be turned toward right as shown in figure by setting the CIRCLE_RIGHT_DIRECTION macro to 1

 

Screen Shot 2012 07 19 at 11 03 55 PM

———————————————————————————————- 

 

 

 

Hope you enjoyed this. Let me know your comments.

Happy Coding 🙂

Thoughts on iOS UDID

There is a lot of buzz with Apple’s rejection of apps accessing UDID API . Let us analyze it.

 

 

What is UDID?

 

UDID is the unique identifier to identify an iOS device uniquely. Apple had exposed an API to access this unique identifier from the start of iOS 2.0 SDK. This made interesting things possible and eventually became a critical API for some of the application’s core functionality. For example. Flurry Analytics, depend on this UDID for reporting number of devices an application is activated. Although, I cannot go through all the list of application using this API, let us do some Impact Analysis and possible problems and their solutions from this move by Apple.

 

When would you use the uniqueIdentifier?

 

I would typically use it in the context where I need to uniquely identify the device in a pool of iOS devices, where this info is send to a centralized place and is used for various purposes. Standalone applications more often does not need this info, unless they have integrated with third party SDK like Flurry, to support non-core features of an application, such as gathering statistics. Therefore, we would not keep this category of applications as these does not have major dependency on UDID.

 

 

What would you do with uniqueIdentifier with a pool of device?

 

Scenario 1:

 

“A scenario could be where the application could act as client and all the instances of the application across the devices are writing some data into the centralized place, could be a Mac or a Centralized Server. In this case the unique identifier would be able to identify the application instance uniquely to resolve the conflicts, say while writing the data to same location.”

 

Syncing

Fig: Scenario 1 showing Application installed in multiple iOS devices syncs with Mac / Server sharing and updating the data

Example: A Simple Notes application where notes are recorded in various iOS devices and then are synchronized with the Mac Application, where the Mac Application acting as a centralized unit.

 

Scenario 2:

 

“Another scenario would be to individually track the number of devices in which the application is activated which helps the sales people to pitch up their sales or we can find them in many of the third party ads which aid in gaining statistics of the application”

 

Example: Analytics SDK like Flurry, InMobi and so on.

 

While the first scenario helps the application in its core functionality, the second scenario is matter of statistics that helps drive the sales. However, accessing a unique identifier of a device without knowledge is a breach of privacy which i believe the motive behind apple deprecating this API.

 

Before digging deep, Let us look at the alternative solution from Apple?

 

Special Considerations:

 

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

 

Well, CFUUIDCreate does create the unique identifier, but will that be sufficient to identify the Device uniquely?? Wait, am I sounding wrong! Your read it right.

Although Apple recommend to create unique identifier and store it in defaults, it works fine as long as the app isn’t deleted and re-installed by the user. Since, doing that would delete the defaults database and upon re-installing a fresh unique identifier would be created which defeats our purpose.

 

Let us track back and see what exactly we need

“We need to find a way where an application would identify uniquely against its clone across multiple devices.”

The critical requirement here is not creating a unique identifier, but persisting it from the time application is installed on a device till literally the lifetime of the device and not the application. Uh!!

There are many solutions floating around like the one from crashlytics, where they achieve the persistence by storing the custom unique identifier in the UIPasteboard. However, there are couple of cons here

  • Apple does not guarantee that the Pasteboard data persists permanently across OS upgrades or reboot
  • Any other application can access this data or override them and one need to ensure that this would be in un-readable form for other that the application which created it.

 

My Solution (Intermediate):

The solution is to change the way we modelled our application behavior. For you to understand, let me divide the iOS era into two.

Pre-iCloud & Post-iCloud.

In Pre-iCloud we used to treat each iOS device as a separate one even though they are owned by ( literally under same apple id) single person. This means that an app in iPhone would have different state than the one in iPad, and probably a External Sync would be required to get them into single state.

In Post-iCloud era, as a developer, one should not distinguish between an application installed in two iOS device grouped under single Apple ID, which is strong point behind the Apple’s iCloud – “It Just Works”. i.e the iCloud make sure that all the data and state information would be consisted across the iOS devices grouped under single Apple ID.

With that differentiation, the solution would be:

“Create a unique identifier as suggested by the Apple and  store them in defaults as wells as in iCloud. Check NSUbiquitousKeyValueStore or using this short piece of library from Mugunth Kumar which I liked, for storing into iCloud. So Even if the App is deleted, the same ID would be retrieved back from iCloud, unless your iCloud is reset which accom”

NOTE: We could use a same approach for tracking the number of apps installed with the difference being the count would be number of users installed the application rather than the number of devices using it.

 

What are your thoughts on this?

Thoughts on iOS UDID

There is a lot of buzz with Apple’s rejection of apps accessing UDID API . Let us analyze it.

 

 

What is UDID?

 

UDID is the unique identifier to identify an iOS device uniquely. Apple had exposed an API to access this unique identifier from the start of iOS 2.0 SDK. This made interesting things possible and eventually became a critical API for some of the application’s core functionality. For example. Flurry Analytics, depend on this UDID for reporting number of devices an application is activated. Although, I cannot go through all the list of application using this API, let us do some Impact Analysis and possible problems and their solutions from this move by Apple.

 

When would you use the uniqueIdentifier?

 

I would typically use it in the context where I need to uniquely identify the device in a pool of iOS devices, where this info is send to a centralized place and is used for various purposes. Standalone applications more often does not need this info, unless they have integrated with third party SDK like Flurry, to support non-core features of an application, such as gathering statistics. Therefore, we would not keep this category of applications as these does not have major dependency on UDID.

 

 

What would you do with uniqueIdentifier with a pool of device?

 

Scenario 1:

 

“A scenario could be where the application could act as client and all the instances of the application across the devices are writing some data into the centralized place, could be a Mac or a Centralized Server. In this case the unique identifier would be able to identify the application instance uniquely to resolve the conflicts, say while writing the data to same location.”

 

Syncing

Fig: Scenario 1 showing Application installed in multiple iOS devices syncs with Mac / Server sharing and updating the data

Example: A Simple Notes application where notes are recorded in various iOS devices and then are synchronized with the Mac Application, where the Mac Application acting as a centralized unit.

 

Scenario 2:

 

“Another scenario would be to individually track the number of devices in which the application is activated which helps the sales people to pitch up their sales or we can find them in many of the third party ads which aid in gaining statistics of the application”

 

Example: Analytics SDK like Flurry, InMobi and so on.

 

While the first scenario helps the application in its core functionality, the second scenario is matter of statistics that helps drive the sales. However, accessing a unique identifier of a device without knowledge is a breach of privacy which i believe the motive behind apple deprecating this API.

 

Before digging deep, Let us look at the alternative solution from Apple?

 

Special Considerations:

 

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

 

Well, CFUUIDCreate does create the unique identifier, but will that be sufficient to identify the Device uniquely?? Wait, am I sounding wrong! Your read it right.

Although Apple recommend to create unique identifier and store it in defaults, it works fine as long as the app isn’t deleted and re-installed by the user. Since, doing that would delete the defaults database and upon re-installing a fresh unique identifier would be created which defeats our purpose.

 

Let us track back and see what exactly we need

“We need to find a way where an application would identify uniquely against its clone across multiple devices.”

The critical requirement here is not creating a unique identifier, but persisting it from the time application is installed on a device till literally the lifetime of the device and not the application. Uh!!

There are many solutions floating around like the one from crashlytics, where they achieve the persistence by storing the custom unique identifier in the UIPasteboard. However, there are couple of cons here

  • Apple does not guarantee that the Pasteboard data persists permanently across OS upgrades or reboot
  • Any other application can access this data or override them and one need to ensure that this would be in un-readable form for other that the application which created it.

 

My Solution (Intermediate):

The solution is to change the way we modelled our application behavior. For you to understand, let me divide the iOS era into two.

Pre-iCloud & Post-iCloud.

In Pre-iCloud we used to treat each iOS device as a separate one even though they are owned by ( literally under same apple id) single person. This means that an app in iPhone would have different state than the one in iPad, and probably a External Sync would be required to get them into single state.

In Post-iCloud era, as a developer, one should not distinguish between an application installed in two iOS device grouped under single Apple ID, which is strong point behind the Apple’s iCloud – “It Just Works”. i.e the iCloud make sure that all the data and state information would be consisted across the iOS devices grouped under single Apple ID.

With that differentiation, the solution would be:

“Create a unique identifier as suggested by the Apple and  store them in defaults as wells as in iCloud. Check NSUbiquitousKeyValueStore or using this short piece of library from Mugunth Kumar which I liked, for storing into iCloud. So Even if the App is deleted, the same ID would be retrieved back from iCloud, unless your iCloud is reset which accom”

NOTE: We could use a same approach for tracking the number of apps installed with the difference being the count would be number of users installed the application rather than the number of devices using it.

 

What are your thoughts on this?

Capturing Exceptions while debugging

This one is a simple but could be time-saving 🙂

Scenario: If you are debugging and caught with awkward situation where the application crashes with an exception, like NSInvalidArgumentException and so on, but never take you to the place in the code where the problem exists.

 

Solution:

Remember, This solution is for Xcode 4.2.1 for Lion.

1.  Select View->Navigators->Show Breakpoint Navigator

Screen Shot 2012 02 22 at 4 42 58 PM

2. At the Bottom-left cornet, Click the ‘+’ symbol and Select ‘Add Exception Breakpoint’ Menu

Screen Shot 2012 02 22 at 4 43 20 PM

3. In the popped-up window you may select [All | Objective-C | C++ ] options to select what type of Exception should the execution stop.

Screen Shot 2012 02 22 at 4 44 15 PM

 

4. Click Done.

Restart your debug process and you should see the line of code that is causing the hassle for you 🙂

 

Courtesy: Apple Developer Document.

 

 

An Idea for replacement of TweetLonger!

Hey Folks,

Just got this crazy idea which I would like to share.

I was just annoyed for the way we have to read the tweets with 140+ characters. With most of the twitter clients ( almost all ) it takes the user to a website to read the whole tweet which in the process is truncating the user experience of reading the tweets within the client and disconnecting the user from the twitter client.

With due respect for 140 characters limit twitter has placed, we could use below trick to solve this issue. This trick uses the in-reply-to feature of the twitter and the ability of most twitter clients to align the chain of tweets (tweets which have been originated as a reply of other tweet) in a linear fashion which helps read the broken tweets without any fuss.

 

Screen shot 2011-11-09 at 8.51.57 PM.png

Fig: A Snapshot of Linked tweets from Twitter for Mac Read the text in the image excluding the twitter handle (i.e. bharath2020) at the start of each tweet.

 

Screen shot 2011-11-09 at 9.10.31 PM.png

Fig: One more way of displaying linked tweets by Twitter Application for Mac

 

This trick could be deployed in all twitter clients with the user typing the whole tweet and twitter client will takes care of breaking the tweets and creating a link between them,

Let me know what do you think of this.

[self class] and static methods in Objective-C

Its been 5+ years of Objective-C programming and If I turn back and see, I have still a lot to learn.

I recently was working on a project, where a small design mistake look costlier. To overcome that, I had to override a set of static methods.

Let me give some insight into what happened before this.

 

I have seen many people use [self class] method in a static method, and I had always thought (my fault, i did not test it 🙁 ) that this would be always equal to the class name where the method is defined. But, I was wrong

 

So I had the following static method to create the Message model object

 

+(BBMessage*)newMessage

{

return [[[BBMessage alloc] init] autorelease];

}

+(BBMessage*)messageFromDictionary:(NSDictionary*)messageInfoDict

{

BBMessage *newMessage = [BBMessage newMessage];

….

}

 

This method was widely used to create the BBMessage object throughout the application. As it turned out be at the near end of the project, I had to add a subclass of BBMessage named BBHistoryMessage. However, the difference between BBHistoryMessage and BBMessage was a couple of  attributes in BBHistoryMessage, but their creation using method messageFromDictionary: remained same.

However, since it had [BBMessage newMessage] statement, the object created by messageFromDictionary: always created BBMessage instance rather than BBHistoryMessage’s instance

This is when I realized that replacing the appearances of BBMessage class name with [self class] as the [self class] would return the name of the class which invoked the method

 

For eg: if the BBHistoryMessage class  is used to invoke messageFromDictionary: then [self class] will be BBHistoryMessage class and hence newMessage would be creating BBHistoryMessage Class.

 

 

Pattern Drawing with CGPattern in iOS or Mac

If you are looking for help on how to stroke or fill up a pattern in iOS or Mac OS X, then You have landed at the right place.

NOTE: A reader of this post is assumed to have prior knowledge of custom drawing in iOS’s UIView, CGContext, and Quartz 2D basics

You can find the Code sample from Github

The Sample code demonstrates the following things:

  • Creation of 3 Different kinds of patterns using CGPattern
  • In the Sample, tap “Change Pattern” to switch to next pattern
  • Use the slider, to increase the size of pattern cell

pattern is an image, usually small, used for filling regions by tiling, that is, by placing copies of the pattern side by side like ceramic tiles. Here we see how we can achieve pattern filling in iOS or Mac using CGPattern.

A step by step explanation on usage of CGPatterns

Quartz draw the patterns using cell based drawing technique, where it would provide us the option to draw a single pattern cell in a context, and uses the context to tile across the remaining area evenly.

STEP 1 : Create a CGPattern instance as below

//Pattern Callback methods

// drawPatternCell – callback to draw a single cell

//PatternReleaseInfoCallback – invoked when a pattern is released

CGPatternCallbacks callBack;

callBack.drawPattern = &drawPatternCell;

callBack.releaseInfo = &PatternReleaseInfoCallback;

callBack.version = 0;

 

// param1 – &patters_types[patternCount] – a context info, here which defines which pattern to be drawn


// param2 – rect of a single pattern cell

 

// param3 – transformation matrix

 

// offsetX – a offset or horizontal gap between each cell.. minimum should be width of the cell

 

// offsetY – a offset of vertical gap between each cell. minimum should be heigh of the cell

 

// Style of – how the pattern cell are to be placed where are drawn on a region bigger than the single pattern cell

 

// shouldColor –   a pattern can also be used as a mask, where the color is applied during the actual context where the pattern is drawn. So, literally you have to say true, if the pattern cell can chose its color, or no if the color at its main context is to be chosen

 

// callback – 2 callbacks encapsulated in a struct CGPatterCallbacks

 

_patterns[patternCount] = CGPatternCreate(&patters_types[patternCount], CGRectMake(0.0, 0.0, PATTERN_CELL_WIDTH, PATTERN_CELL_HEIGHT), CGAffineTransformIdentity, PATTERN_CELL_WIDTH, PATTERN_CELL_HEIGHT, kCGPatternTilingConstantSpacing, true, &callBack);

 

 

STEP 2:  (Important) define the drawPattern callback as below. This is the place where you are allowed to draw a single cell of a pattern. The drawing technique of pattern cell is same as one would draw in View’s drawRect method or drawing with any CGBitmapContext.

 

Pattern 1 – Chequered flag –

Chequered Flag Pattern

//Chequered Flag

//Fill the entire background with white color

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);

CGContextFillRect(context, CGRectMake(0.0, 0.0, cellWidth, cellHeight));

 

CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);

//Fill the top left quarter of the cell with black

CGContextFillRect(context, CGRectMake(0.0, 0.0, cellWidth/2.0, cellHeight/2.0));

 

//Fill the bottom right quarter of the cell with black

CGContextFillRect(context, CGRectMake(cellWidth/2.0, cellHeight/2.0, cellWidth/2.0, cellHeight/2.0));

 

Pattern 2

pattern_2

//http://www.kitchenbeforeandafter.com/wp-content/uploads/2009/05/kitchen-backsplash-tile-patterns2-300×216.gif

//       /

//     /

//  _ /

//   |_|

//  /  

// /    

///      

 

 

//stroke middle square

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);

CGContextFillRect(context, CGRectMake(0.0, 0.0, cellWidth, cellHeight));

 

 

//stroke diagonal

CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

CGPoint points [] = {{0.0,0.0}, {cellWidth,cellHeight }, {cellWidth,0.0}, {0.0,cellHeight}};

CGContextStrokeLineSegments(context, points, 4);

 

CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);

int num_of_parts = 8;

float partWitdth = cellWidth / num_of_parts;

CGRect middleSpot = CGRectMake(partWitdth * 3, partWitdth*3, 2* partWitdth, 2*partWitdth);

 

CGContextFillRect(context, middleSpot);


Pattern 3

Circular_pattern

The Elements involve in this pattern are a circle drawn with various transformations

  • Circle
  • Semi-Circle
    • Circle shifted towards left by half the width of the cell
    • Circle shifted towards right by half the width of the cell
    • Circle shifted towards top by half the height of the cell
    • Circle shifted towards bottom by half the height of the cell
  • Arc
    • Circle shifted towards left & top by half the width and half the height of the cell respectively
    • Circle shifted towards left & bottom by half the width and half the height of the cell respectively
    • Circle shifted towards right & top by half the width and half the height of the cell respectively
    • Circle shifted towards right & bottom by half the width and half the height of the cell respectively

You can clone a copy of this Sample project from GitHub

STEP 3: Applying the Pattern.

Finally we would be applying the pattern in drawRect method of BBQuartzView in this sample.

// Drawing code

float alpha = 1;

 

//choose the pattern to be filled based on the currentPattern selected

CGContextRef context = UIGraphicsGetCurrentContext();

CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern (NULL);// 6

CGContextSetFillColorSpace (context, patternSpace);// 7

CGColorSpaceRelease (patternSpace);

 

//set the pattern as the Current Context’s fill pattern

 

//we dont need to set any color, as the pattern cell itself has chosen its own color

CGContextSetFillPattern(context, _patterns[_currentPattern],   &alpha);


//We would be filling the entire portion of this view

CGContextFillRect(context, [self bounds]);

  • Choose the pattern that needs to be applied. In this sample, the pattern is chosen based on the _currentPattern variable value (0- Chequered pattern, 1- Pattern2, 3- Pattern3)
  • Patterns are created at the time of initializing the view. In sample, it is in initWithCoder method of BBQuartzView
  • The drawPattern callback is invoked only when the pattern is all set to be drawn. In my case, it is invoked when CGContextFillRect in the above drawing code snippet. You can use this pattern to fill any shape. The selected pattern would also be reflected while using CGContext drawing API like, CGContextFill variants, CGContextFillPath variants
  • The drawPattern Callback is called only once in its lifetime and for subsequent drawing, the pattern cell buffer would be re-used. So resize the single pattern cell, the patterns are re-created

Here is are the pics how the patterns would look like(captured from sample code).

patterns.png

 

You can clone a copy of this Sample project from GitHub

Hope, you find this piece of info useful. Fill in your comments or queries in below comment’s section. Waiting for you comments.

Happy Coding 🙂

AGE Meter LIVE as iChat Status via Apple Script

Necessity is the Mother of Invention” – I just experienced the truth of it. Wait, I haven’t invented anything here. Since, I had the appetite do something new and noticeable on my Birthday, I came with AGE Meter, which displays your AGE as iChat status message, and its LIVE, updated every second

 

iChatStatus

 

I had written an Apple Script to set the Chat Message, and since many people follow my iChat status message, I thought let me update my AGE every second, which is something new in a status message, Right?. It received awesome response and I would like to share this script and let you experience the awesomeness of it.

 

 

NOTE: This script requires Mac OS X 10.4 and above, AppleScript Editor, iChat Messager for Mac OS X , PHP Installed

 

The Script is divided in to two parts

 

1. Apple Script – to update the iChat Message status

 

2. PHP script – to calculate the difference between current date and your Birthdate. This script is invoked by AppleScript and its result (the Age in Years, Months, Days, Hours, Minutes, Seconds ) is piped to AppleScript for final display

 

You can find the script here.

 

Installation

 

1. Unzip the BirthdayCounter.zip, which you have downloaded. Once unzipped, you  should find a “BirthdayCounter” Folder. This folder has two files “BirthdayCounter_AppleScript” and “DateDifference.php”

 

2. Update your Birthdate here in this line in DateDifference.php file, located at the end of the script. Please note that the time should be in GMT.

 

echo dateDiff(“1976-06-23 02:00:00”, “now”) . “n”;

 

3. Open “BirthdayCounter_AppleScript” in Apple Script Editor and Tap Run. There you go, the AGE meter has started.

 

 

Let me know if it looks awesomely for you 🙂

 

 


 

10000 HITS!!

Hey Folks,

This blog just got its 10,000 hit and thank you each one you who have shown good support towards this blog. I think this is just the beginning. Just to give some stat on this short journey, the most liked posts in this blog are

Efficient Memory Handling in UIViewController-Part 1

iOS Open Folder Animation

And Apologize for not updating this blog for past 5 months, I have bee caught up in too many things viz ICC Cricket World Cup 2011(hey India Won it 🙂 ), IPL (RCB made it to Finals) and shifting focus to Android OS.

And lately, burnt my fingers by updating iOS 5 Beta onto my iPad ( unofficially the iPAd 1), and after experiencing its flaws (I don’t like it being tagged as BETA) tried to restore it to 4.3.3 successfully( in an ugly way ) but none of the third party apps are working anymore.

If you are planning to upgrade to iOS 5 BETA, then I would say spend your valuable time onto something else, and if you are still want to do, Make sure you BACKUP YOUR DEVICE before attempting it.

Will get back to you sooner.

All the Best!!

Happy Coding 🙂