2011-07-04 70 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]; 
} 

這工作不錯。我想從該按鈕得到的最後一件事是讓它的標題保持一致。我是新來的three20圖書館,所以我覺得我不明白樣式是如何工作的。我發現每個TTStyle都有next:方法。但是,多種風格如何協同工作?

回答

0

該按鈕的文本對齊方式在-(TTStyle*)toolbarButtonForState: shape: tintColor: font:中定義。所以你需要創建你自己的這個方法。

如果您查看原始文件,您會發現TTTextStyle作爲最後添加的樣式。 TTTextStyle讓你設置textAlignment與便捷初始化

+ (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 

所以你的實現可能看起來像:

- (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

哇=)謝謝您的回答! –

相關問題