Three20:图像使用TTStyles位于TTButton内的文本上方

时间:2012-07-27 19:50:07

标签: objective-c uibutton three20

我正在尝试将TTButton设置为如下所示:

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 个答案:

答案 0 :(得分: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]];
}