Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
users:shilo:extensions:sptextfield_justify [2013/07/17 05:35]
shilo
users:shilo:extensions:sptextfield_justify [2013/07/17 05:36] (current)
shilo [Alignment Values]
Line 1: Line 1:
 +====== SPTextField+Justify ======
 +---- dataentry extension ----
 +type          : extension
 +author_mail ​  : shilo86@gmail.com Shilo White
 +description ​  : A category for Sparrow 2.X that allows a bitmap SPTextField to justify align.
 +lastupdate_dt : 2013-07-16
 +compatible ​   : v2.X
 +depends ​      : ​
 +tags          : text, textfield, justify, justified, justification
 +homepage_url ​ : https://​gist.github.com/​Shilo/​6017433
 +download_url ​ : https://​gist.github.com/​Shilo/​6017433/​download
 +----
  
 +===== Alignment Property Values =====
 +
 +<code objc>
 +#define SPVAlignJustify ​              ​SPVAlignBottom+1
 + 
 +#define SPHAlignJustify ​              ​SPHAlignRight+1
 +#define SPHAlignJustifyLastLineLeft ​  ​SPHAlignJustify+1
 +#define SPHAlignJustifyLastLineCenter SPHAlignJustifyLastLineLeft+1
 +#define SPHAlignJustifyLastLineRight ​ SPHAlignJustifyLastLineCenter+1
 +</​code>​
 +
 +===== Sample =====
 +
 +{{http://​f.cl.ly/​items/​1N0z27322T0H2Y3L0s43/​Screen%20Shot%202013-07-16%20at%208.18.45%20PM.png}}
 +
 +===== Usage =====
 +
 +<code objc>
 +//
 +//  Game.m
 +//  AppScaffold
 +//
 +
 +#import "​Game.h"​
 +#import "​SPTextField+Justify.h"​
 +
 +@implementation Game
 +
 +- (id)init
 +{
 +    if ((self = [super init]))
 +    {
 +        Sparrow.stage.color = 0xffffff;
 +        ​
 +        CGRect screenBounds = [UIScreen mainScreen].bounds;​
 +        float stageWidth = screenBounds.size.height;​
 +        float stageHeight = screenBounds.size.width;​
 +        ​
 +        NSString *text = @"​Sparrow does not cost a dime. Download and use it right away, no strings attached. Drop your inhouse engine and focus on your games right now!";
 +        ​
 +        [SPTextField registerBitmapFontFromFile:​@"​Helvetica.fnt"​];​
 +        ​
 +        for (SPHAlign hAlign=SPHAlignLeft;​ hAlign<​=SPHAlignJustifyLastLineRight;​ hAlign++) {
 +            for (SPVAlign vAlign=SPVAlignTop;​ vAlign<​=SPVAlignJustify;​ vAlign++) {
 +                NSString *hText = [NSString stringWithFormat:​@"​hAlign:​\n%@\n\n",​ [self hAlignToString:​hAlign]];​
 +                NSString *vText = [hText stringByAppendingFormat:​@"​vAlign:​\n%@\n\n",​ [self vAlignToString:​vAlign]];​
 +                ​
 +                SPTextField *textField = [SPTextField textFieldWithText:​[vText stringByAppendingString:​text]];​
 +                textField.fontName = @"​Helvetica";​
 +                textField.fontSize = 11;
 +                textField.width = stageWidth/​7;​
 +                textField.height = stageHeight/​4;​
 +                textField.x = hAlign*textField.width;​
 +                textField.y = vAlign*textField.height;​
 +                textField.hAlign = hAlign;
 +                textField.vAlign = vAlign;
 +                textField.border = YES;
 +                if (vAlign >= SPVAlignJustify || hAlign >= SPHAlignJustify)
 +                    textField.color = 0x0000ff;
 +                [self addChild:​textField];​
 +            }
 +        }
 +    }
 +    return self;
 +}
 +
 +- (NSString *)hAlignToString:​(SPHAlign)hAlign {
 +    if (hAlign == SPHAlignLeft)
 +        return @"​SPHAlignLeft";​
 +    else if (hAlign == SPHAlignCenter)
 +        return @"​SPHAlignCenter";​
 +    else if (hAlign == SPHAlignRight)
 +        return @"​SPHAlignRight";​
 +    else if (hAlign == SPHAlignJustify)
 +        return @"​SPHAlignJustify";​
 +    else if (hAlign == SPHAlignJustifyLastLineLeft)
 +        return @"​SPHAlignJustifyLastLineLeft";​
 +    else if (hAlign == SPHAlignJustifyLastLineCenter)
 +        return @"​SPHAlignJustifyLastLineCenter";​
 +    else if (hAlign == SPHAlignJustifyLastLineRight)
 +        return @"​SPHAlignJustifyLastLineRight";​
 +    else
 +        return @"​unknown";​
 +}
 +
 +- (NSString *)vAlignToString:​(SPVAlign)vAlign {
 +    if (vAlign == SPVAlignTop)
 +        return @"​SPVAlignTop";​
 +    else if (vAlign == SPVAlignCenter)
 +        return @"​SPVAlignCenter";​
 +    else if (vAlign == SPVAlignBottom)
 +        return @"​SPVAlignBottom";​
 +    else if (vAlign == SPVAlignJustify)
 +        return @"​SPVAlignJustify";​
 +    else
 +        return @"​unknown";​
 +}
 +@end
 +</​code>​
 +
 +===== Changelog =====
 +
 +  * //​2013/​07/​16 08:29//: First public version
 +
 +===== Source Code =====
 +
 +%gist(6017433)%
 +
 +===== Discussion =====
 +
 +//No comments so far. Feel free to edit this part of the page.//
  users/shilo/extensions/sptextfield_justify.txt · Last modified: 2013/07/17 05:36 by shilo
 
Powered by DokuWiki