2011-07-04 6 views
0

私はTTButtonを作成する方法を知っている:TTButtonsのタイトルを左揃えにする方法は?

TTButton *epriceButton = [TTButton buttonWithStyle:@"epriceButton:"]; 

そして、私は方法があります。素敵な作品

- (TTStyle *)epriceButton:(UIControlState)state { 
    TTShape* shape; 
    shape = [TTRoundedRectangleShape shapeWithRadius:4.5]; 
    UIColor* tintColor = RGBCOLOR(8, 101, 191); 
    return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil]; 
} 

を。そのボタンから最後に1つ欲しいのは、そのタイトルを左揃えにすることです。私は3ライブラリーが初めてだから、スタイルの仕組みを理解できないと思う。私は各TTStyleにnext:メソッドがあることを発見しました。しかし、複数のスタイルがどのように連動するのでしょうか

答えて

0

ボタンのテキストの配置は、-(TTStyle*)toolbarButtonForState: shape: tintColor: font:の内側に定義されています。したがって、このメソッドの独自のバージョンを作成する必要があります。

オリジナルを調べると、追加される最後のスタイルとしてTTTextStyleが見つかるでしょう。 TTTextStyleみましょうあなたはだからあなたの実装は次のようになります便利な初期化子

+ (TTTextStyle*)styleWithFont:(UIFont*)font color:(UIColor*)color 
       minimumFontSize:(CGFloat)minimumFontSize 
        shadowColor:(UIColor*)shadowColor shadowOffset:(CGSize)shadowOffset 
       textAlignment:(UITextAlignment)textAlignment 
      verticalAlignment:(UIControlContentVerticalAlignment)verticalAlignment 
       lineBreakMode:(UILineBreakMode)lineBreakMode numberOfLines:(NSInteger)numberOfLines 
         next:(TTStyle*)next 

でtextAlignmentを設定します。

- (TTStyle*)myButtonForState:(UIControlState)state shape:(TTShape*)shape 
         tintColor:(UIColor*)tintColor font:(UIFont*)font { 
    UIColor* stateTintColor = [self toolbarButtonColorWithTintColor:tintColor forState:state]; 
    UIColor* stateTextColor = [self toolbarButtonTextColorForState:state]; 

    return 
    [TTShapeStyle styleWithShape:shape next: 
    [TTInsetStyle styleWithInset:UIEdgeInsetsMake(2, 0, 1, 0) next: 
    [TTShadowStyle styleWithColor:RGBACOLOR(255,255,255,0.18) blur:0 offset:CGSizeMake(0, 1) next: 
    [TTReflectiveFillStyle styleWithColor:stateTintColor next: 
     [TTBevelBorderStyle styleWithHighlight:[stateTintColor multiplyHue:1 saturation:0.9 value:0.7] 
             shadow:[stateTintColor multiplyHue:1 saturation:0.5 value:0.6] 
             width:1 lightSource:270 next: 
     [TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, -1, 0, -1) next: 
     [TTBevelBorderStyle styleWithHighlight:nil shadow:RGBACOLOR(0,0,0,0.15) 
             width:1 lightSource:270 next: 
     [TTBoxStyle styleWithPadding:UIEdgeInsetsMake(8, 8, 8, 8) next: 
      [TTImageStyle styleWithImageURL:nil defaultImage:nil 
           contentMode:UIViewContentModeScaleToFill size:CGSizeZero next: 
      [TTTextStyle styleWithFont:font color:stateTextColor 
             minimumFontSize:14.0 
              shadowColor:[UIColor colorWithWhite:0 alpha:0.4] shadowOffset:CGSizeMake(0, -1) 
             textAlignment:UITextAlignmentLeft 
            verticalAlignment:UIControlContentVerticalAlignmentCenter 
             lineBreakMode:UILineBreakModeWordWrap numberOfLines:1 
               next:nil]]]]]]]]]]; 
} 
+0

おっと=)あなたの答えをありがとう! –

関連する問題