2012-07-27 34 views
0

我想要的風格TTButton圖像位於上面的文字中TTButton出現類似如下:Three20:使用TTStyles

http://tinypic.com/r/29c3oyh/6

你會發現,圖像和文本都是中心對齊在TTButton中,圖像位於文本上方。無論TTBoxStyle和訂購的組合如何,我都無法同時獲得圖像和文本的正確對齊方式。

- (TTStyle*)happyfaceIcon:(UIControlState)state { 
return [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeCenter size:CGSizeMake(40, 40) next: 
     [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(0, 20, 0, 0) next:nil]]; 
} 

- (TTStyle*)happyfaceButton:(UIControlState)state { 
return [TTShapeStyle styleWithShape:[TTRectangleShape shape] next: 
     [TTSolidBorderStyle styleWithColor:[UIColor blackColor] width:1 next: 
     [TTSolidFillStyle styleWithColor:[UIColor grayColor] next: 
      [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(45, 2, 5, 2) next: 
      [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:10] 
           color:[UIColor blackColor] textAlignment:UITextAlignmentCenter next: 
      [TTPartStyle styleWithName:@"image" style:TTSTYLESTATE(happyfaceIcon:, state) next: nil 
      ]]]]]]; 
} 

回答

1

好吧,它看起來很直截了當。我只需要看TTLauncherButton來查看答案。

基本上TTButton屬性isVertical = YES清除了所有問題。

這是我最後的風格,以及如果有人有興趣

- (TTStyle*)shortcutIcon:(UIControlState)state { 
TTStyle* style = 
[TTBoxStyle styleWithMargin:UIEdgeInsetsMake(-7, 0, 11, 0) next: 
    [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeCenter 
          size:CGSizeZero next:nil]]; 

if (state == UIControlStateHighlighted || state == UIControlStateSelected) { 
    [style addStyle: 
    [TTBlendStyle styleWithBlend:kCGBlendModeSourceAtop next: 
     [TTSolidFillStyle styleWithColor:RGBACOLOR(0,0,0,0.5) next:nil]]]; 
} 

return style; 
} 

- (TTStyle*)shortcutButton:(UIControlState)state { 
return 
[TTPartStyle styleWithName:@"image" style:TTSTYLESTATE(shortcutIcon:, state) next: 
[TTTextStyle styleWithFont:[UIFont fontWithName:@"Frutiger-Light" size:15] color:TTSTYLEVAR(shortcutTextColor) 
      minimumFontSize:11 shadowColor:nil 
       shadowOffset:CGSizeZero next:nil]]; 
}