TTStyle的缩进实现
在写一些小的应用时候遇见一个需求,需要在view前面做一个list-type,显然需要一个小缩进,不知到three20有没有其他的解决方案,方正我处理方式是写另一个style。使用方法是这样的。
[TTSolidFillStyle styleWithColor:color next: [TTAreaStyle styleWithRect:CGRectMake(0, 0, Indent, 18.0) style: [TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(255, 255, 255) color2:RGBCOLOR(0, 0, 0) next:nil] next: [TTBoxStyle styleWithPadding:UIEdgeInsetsMake(0, Indent + Gap, 0, 0) next: [TTTextStyle styleWithFont:nil color:TTSTYLEVAR(linkTextColor) minimumFontSize:14 shadowColor:[UIColor colorWithWhite:255 alpha:0.4] shadowOffset:CGSizeMake(0, -1) textAlignment:UITextAlignmentLeft verticalAlignment:UIControlContentVerticalAlignmentCenter lineBreakMode:UILineBreakModeWordWrap numberOfLines:0 next:nil ]]]];
代码如下
//
// TTAreaStyle.h
// infzm
//
// Created by lin waiwai on 1/19/11.
// Copyright 2011 __waiwai__. All rights reserved.
//
@interface TTAreaStyle : TTStyle {
CGRect _rect;
TTStyle *_style;
}
@property (nonatomic, retain) TTStyle* style;
@property (nonatomic) CGRect rect;
+(TTAreaStyle*)styleWithRect:(CGRect)rect style:(TTStyle*)stylez next:(TTStyle*)next;
@end
//
// TTAreaStyle.m
// infzm
//
// Created by lin waiwai on 1/19/11.
// Copyright 2011 __waiwai__. All rights reserved.
//
#import "TTAreaStyle.h"
// Core
#import "Three20Core/TTCorePreprocessorMacros.h"
@implementation TTAreaStyle
@synthesize rect = _rect;
@synthesize style = _style;
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_style);
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Class public
///////////////////////////////////////////////////////////////////////////////////////////////////
+(TTAreaStyle*)styleWithRect:(CGRect)rect style:(TTStyle*)stylez next:(TTStyle*)next; {
TTAreaStyle* style = [[[self alloc] initWithNext:next] autorelease];
style.rect = rect;
style.style = stylez;
return style;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTStyle
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)draw:(TTStyleContext*)context {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect rect = context.frame;
CGContextSaveGState(ctx);
[context.shape addToPath:rect];
CGContextClip(ctx);
CGContextClipToRect(ctx,self.rect);
[self.style draw:context];
CGContextRestoreGState(ctx);
return [self.next draw:context];
}
@end

.jpg)
.jpg)