Wednesday, August 24, 2011

How to do vertical alignment for UILabels

I wrote something about that but I don't remember where :). Anyway, the easiest way is to add a method to the UILabel class.

Include in your file (or create a new one) this interface to extend the current UILabel one:
@interface UILabel (VerticalAlign)
- (void)alignTop;
@end
Add the method code in the .m file:
- (void)alignTop {
    CGSize fontSize = [self.text sizeWithFont:self.font];
    double finalHeight = fontSize.height * self.numberOfLines;
    double finalWidth = self.frame.size.width;    
    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
    int newLinesToPad =
(finalHeight  - theStringSize.height) / fontSize.height;
    for(int i=0; i
        self.text = [self.text stringByAppendingString:@"\n "];
}

Done, now you can use this new method
[YourUILabel alignTop];

Hope help!

Wednesday, August 17, 2011

How to install ImageMagick in a Mac for MAMP

Hello,

First of all we need some tools:

For installing MacPort download the last version and on a terminal write:
$ sudo port selfupdate
If it doesn't work it's because you need to add the new path to the system PATH variable, ie:
$ export PATH=$PATH:/opt/local/bin
$ export MANPATH=$MANPATH:/opt/local/share/man
$ export INFOPATH=$INFOPATH:/opt/local/share/info
Now, we can install the ImageMagick and GhostScript
$ sudo port install ImageMagick
$ sudo port install ghostscript
Now it's time to configure the MAMP
$ vi /Applications/MAMP/Library/bin/envvars
and comments the lines

#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
and add a new line at the end of the file
export PATH="$PATH:/opt/local/bin"
and done!!!

Try it out
exec(‘convert -resize 640×480 -quality 70 test.eps test.jpg’);

Hope help!