Friday, January 28, 2011

Time delay in a iphone development

The easiest way is to delay the thread like this:

[NSThread sleepForTimeInterval:2.0];


Hope help

How to write a UILabel programmatically

I need to add a label that shows a loading string. One way to do it is


UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2)-75, 0.0, 150.0, 43.0) ];
scoreLabel.textAlignment = UITextAlignmentCenter;
scoreLabel.textColor = [UIColor whiteColor];
scoreLabel.backgroundColor = [UIColor blackColor];
scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(18.0)];
[self addSubview:scoreLabel];
scoreLabel.text = [NSString stringWithFormat: @"%d", @"Loading..."];


Bye

Sunday, January 16, 2011

How to write text in an iPhone CGContextShowTextAtPoint

Hi,

Today I need to write a text in my iPhone using the CGContextShowTextAtPoint. First problem is that by default the text will appear inverted so we need to tranform it. The solution is for exmaple:

void drawText (CGContextRef myContext, char *title, int x, int y, int w, int h)
{
CGContextSelectFont (myContext, "Arial", h/10, kCGEncodingMacRoman);
CGContextSetRGBFillColor (myContext, 0, 0, 0, 0.99);
CGContextSetTextMatrix(myContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
CGContextShowTextAtPoint (myContext, x, y, title, strlen(title));
}


The key is on the
CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)
transformation.

Hope help!!

Tuesday, January 11, 2011

Subversion back-up

Today's problem is how to make a svn backup??

Easy pissy! Only two commands:

svnadmin dump path/to/repository | gzip > dumpfile.gz


for generate the backup file and

gunzip -c dumpfile.gz | svnadmin load path/to/repository


for restore the back-up copy.

If we want to export without version numbers (production copy):

svn export svn+ssh://usuario@server.com/home/usuario/svn/project/trunk /local/path


Nothing more for today!!

Have a nice day

Sunday, January 2, 2011

How to convert iphone accelerometer raw data to degrees

Hello and Happy new year!!

Someone asked me yesterday how can we convert the iphone accelerometer outputs to degrees. Well, it's easy. We are going to use the function

CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180/M_PI;};


and then, the only thing we need to do is

CGFloat angleXY=RadiansToDegrees(atan2(acceleration.y, acceleration.x));


For example, if we want to show this data in a UITextField called textXY

textXY.text=[NSString stringWithFormat:@"%f", angleXY];


Hope help!!