Thursday, 13 October 2011

Farewell, Master


Today I read the latest sad news. Denis Ritchie, co-writer and co-ideator of UNIX and C programming language, died at 70.
Thank you for your immense contribute to computer science.

int main(int argc, char** argv){
   printf("Farewell mr. Ritchie.\n");
   printf("You made our tools.\n");
   printf("You made the True Operating System.\n");
   printf("You made us programmers.\n");
   printf("You made us hackers.\n");
   return 0;
}

Thursday, 6 October 2011

Thank you

Thank you for NeXT and its codebase.
Thank you for the Macintosh, a real personal computer, wich does what a PC should do in 2011.
Thank you for iPhone.
Thank you for iPad, the "magical" device.
Thank you for creating this framework, giving me the opportunity to work as a Real Programmer in a Real Programming Language.
Thank you, Steve.

Wednesday, 14 September 2011

iPhone SDK Troubles: ios SDK blurry fonts

A very annoying thing is when you programmatically create contents for a UITableViewCell and text in UIlabels appears blurry. Why? The answer is simpler than you can think: you positioned your UILabels in the wrong place. Probably, you positioned your UILabel:
//At allocation time
UILabel* l=[[UILabel alloc] initWithRect:CGRectMake(x,y,w,h)];

//or after
l.frame=CGRectMake(x,y,w,h);
Now, be careful: what's the meaning of (x,y,w,h)? They're floating point values. When placed in a UIView, they must have no fractional part. If you specify it with (e.g.)
(1.0f, 3.0f, 200.0f, 400.0f)
your label will not appears blurry. If you calculate UILabel's frame, you must call floor function to force to zero fractional part.
float a=1.0f;
float b=3.0f;
float c=200.0f;
float d=400.0f;

l.frame=CGRectMake(
        floor(x/3.0f),
        floor(y/3.0f),
        floor(w/3.0f),
        floor(h/3.0f)
    );
Texts appear blurry when coordinates aren't approximate to nearest integer. Floor force this approximation. Now your text will appear sharp as a japanese sword :)

Tuesday, 9 August 2011

iPhone SDK Troubles: Rotating scrollview image gallery



Everybody love iOS interface and its "magic" appeal: fluid rotations, fluid swipe, ecc. A iOS programmer knows that there's a lot of work under that magic. If you try to realize a simple image gallery, you'll have some surprises when you'll try to rotate it:

  1. your image will not be located on view's center, but on a corner.
  2. if you forced your gallery to scroll to a certain page with scrollToRect, then you'll see all your precedent images in a fast scroll, even if you set parameter Animated to NO
  3. if you need to scroll after rotation, you'll see a rotation around a corner
Solutions I found are:
  1. Point 1: when detecting a rotation, (willRotateToInterfaceOrientation), you have to resize:
    • Images on the scrollview
    • scrollview content

  2. Points 2 & 3: you must cover gallery's scrollview with a UIImageView containing current gallery image, hiding all scrollview animations. The "cover" will rotate around screen center, giving a more professional (and Apple) look.