// // SimpleGride.m // Apex Mobile // // Created by Ray on 14-3-4. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "SimpleGrid.h" #import "const.h" #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] @implementation SimpleGrid @synthesize griddelegate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } -(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim { NSScanner *theScanner = [NSScanner scannerWithString:html]; NSString *text = nil; while ([theScanner isAtEnd] == NO) { // find start of tag [theScanner scanUpToString:@"<" intoString:NULL] ; // find end of tag [theScanner scanUpToString:@">" intoString:&text] ; // replace the found tag with a space //(you can filter multi-spaces out later if you wish) html = [html stringByReplacingOccurrencesOfString: [ NSString stringWithFormat:@"%@>", text] withString:@""]; } return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html; } -(void) initgrid :(PageData*) pageData { for(UIView* v in self.subviews) { if(v.tag==200)// do not remove refresh control; continue; [v removeFromSuperview]; } self.contentSize = CGSizeMake(0.0,0.0); self.hrefs = [[NSMutableDictionary alloc] init]; self.pageData = pageData; self.hidden = TRUE; self.basetag = MAX_ROW*MAX_COLUMN; self.row_count = [pageData get_count]+1; self.column_count = self.header_aname.count; // self.fullrowselect = true; self.top_line = 2; self.left_line =2; self.right_line =2; self.bottom_line=2; self.line = 1; int columns_width[MAX_COLUMN] ; for(int i=0;i) // UILabel * compute_item = [UILabel alloc]; // TouchLabel * compute_item = [[TouchLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0 )] ; UILabel * compute_item = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0 )] ; NSMutableArray* values = [[NSMutableArray alloc] init]; for(int i=0;icolumns_width[j]) columns_width[j]=compute_item.frame.size.width+padding_h; } } int background_width = 0; for(int i=0;i0) { if(i%2==1) item.backgroundColor = [UIColor whiteColor]; else item.backgroundColor = COLOR(238,238,238,1.0); } else item.backgroundColor = [UIColor lightGrayColor]; // DebugLog(@"size after fit: {x=%f , y=%f}",item.frame.size.width,item.frame.size.height); column_offset += columns_width[j]; [backgroudView addSubview:item]; } } CGSize contentSize; contentSize.height = self.superview.frame.size.height;//background_height+2*background_margin; contentSize.width = background_width+2*background_margin; self.contentSize = contentSize; DebugLog(@"background window : {x=%f , y=%f , width=%f , height=%f }",backgroudView.frame.origin.x,backgroudView.frame.origin.y ,backgroudView.frame.size.width,backgroudView.frame.size.height); [self addSubview:backgroudView]; self.hidden = false; } #pragma mark - Label Gesture - (void)drawSelect:(CGRect)rect { DebugLog(@"drawSelect"); CGContextRef context = UIGraphicsGetCurrentContext(); // CGRect rectt = CGRectMake(100 ,100, 100, 100);//坐标 CGContextSetRGBFillColor(context, 0/ 255.0f, 0/ 255.0f, 0/ 255.0f,0.2);//颜色(RGB),透明度 CGContextFillRect(context, rect); // Drawing code // CGContextRef context = UIGraphicsGetCurrentContext(); // // CGContextSetLineWidth(context, 2.0); // // CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]); // // CGContextMoveToPoint(context, rect.origin.x, rect.origin.y); // // CGContextAddLineToPoint(context, rect.size.width, rect.size.height); // // CGContextStrokePath(context); } -(void)LabelLong:(UILongPressGestureRecognizer*)gestureRecognizer{ if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) { DebugLog(@"长按事件"); if(gestureRecognizer.view.tag - self.basetag < MAX_COLUMN) //header return; // CGRect rect; // if(self.fullrowselect) // { // // rect.origin.x= gestureRecognizer.view.superview.frame.origin.x+self.left_line; // rect.origin.y= gestureRecognizer.view.superview.frame.origin.y+self.left_line; // } //int idx = [t locationInView:self].y / d.cellHeight; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.65]; long row = (gestureRecognizer.view.tag-self.basetag) /100; if(self.fullrowselect) { for(int i=0;i