开发者

How to make TTButtons title left aligned?

开发者 https://www.devze.com 2023-03-17 15:09 出处:网络
I know how to create TTButton: TTButton *epriceButton = [TTButton buttonWithStyle:@\"ep开发者_运维百科riceButton:\"];

I know how to create TTButton:

TTButton *epriceButton = [TTButton buttonWithStyle:@"ep开发者_运维百科riceButton:"];

And I have a method:

- (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]; 
}

That works nice. Last one thing I want from that button is to have its title left aligned. I'm new to three20 library, so I think I don't understand how styles work. I found that each TTStyle has next: method. But how multiple styles work together?


The text alignment for the button is defined inside -(TTStyle*)toolbarButtonForState: shape: tintColor: font:. So you will need to create your own version of this method.

If you look into the original you'll find a TTTextStyle as the last style being added. TTTextStyle let's you set the textAlignment with the convenient initializer

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

So your implementation might look like:

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

精彩评论

暂无评论...
验证码 换一张
取 消