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

합니다. 마지막으로 버튼에서 원하는 것은 제목을 왼쪽으로 정렬하는 것입니다. 3 층 라이브러리가 처음인데 스타일이 어떻게 작동하는지 이해하지 못한다고 생각합니다. 각 TTStyle에는 next : 메소드가 있습니다. 그러나 여러 스타일이 함께 작동하는 방식은 무엇입니까?

답변

0

버튼의 텍스트 정렬은 -(TTStyle*)toolbarButtonForState: shape: tintColor: font: 안에 정의되어 있습니다. 따라서이 방법의 자체 버전을 만들어야합니다.

원본을 들여다 보면 추가되는 마지막 스타일로 TTTextStyle이 있습니다.

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

워 =이) 답변 주셔서 감사합니다 : 당신이

+ (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을 설정하자 TTTextStyle! –

관련 문제