这里的故事,之前,我使用xcode 4并使用库ECSSlidingView菜单,它工作得很好但是在我使用xcode 5克隆到新项目后,很多事情搞砸了,即使没有代码更改!
视图向上移动,并且不显示imageview
都使用这段代码(告诉我你是否还需要更多)
对于CellView @implementation SideMenuTableViewCell
@synthesize indexpath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setAccessoryCheckmarkColor:[UIColor whiteColor]];
[self setDisclosureIndicatorColor:[UIColor whiteColor]];
[self setAccessoryCheckmarkColor:[UIColor whiteColor]];
// Disable this as this will overlaped with draw to stroke line
//UIView * backgroundView = [[UIView alloc] initWithFrame:self.bounds];
//[backgroundView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
//[backgroundView setBackgroundColor:[CustomConfiguration CFG_THEME_COLOR_BLUE]];
//[self setBackgroundView:backgroundView];
//
[self setBackgroundColor:[CustomConfiguration CFG_THEME_COLOR_BLUE]];
[self setBackgroundColor:[UIColor clearColor]];
[self.textLabel setTextColor:[CustomConfiguration CFG_THEME_COLOR_YELLOW]];
[self.textLabel setFont:[CustomConfiguration CFG_THEME_FONT_LARGEBUTTON]];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType{
[super setAccessoryType:accessoryType];
if(accessoryType == UITableViewCellAccessoryCheckmark){
MMCustomCheckmark * customCheckmark = [[MMCustomCheckmark alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
[customCheckmark setColor:self.accessoryCheckmarkColor];
[self setAccessoryView:customCheckmark];
}
else if(accessoryType == UITableViewCellAccessoryDisclosureIndicator){
MMDisclosureIndicator * di = [[MMDisclosureIndicator alloc] initWithFrame:CGRectMake(0, 0, 10, 14)];
[di setColor:self.disclosureIndicatorColor];
[self setAccessoryView:di];
}
else {
[self setAccessoryView:nil];
}
}
// Configure cell.imageView size and position
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(50, 50, 25, 25);
}
-(void)drawRect:(CGRect)rect{
if (self.indexpath.row > 0) {
return;
}
//// General Declarations
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
//// Frames
CGRect frame = CGRectMake(0, -1, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)+1);
UIColor *customWhite = [UIColor colorWithRed:251.0/255.0 green:251.0/255.0 blue:249.0/255.0 alpha:1];
//// Fill Drawing
CGRect fillRect = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(frame), CGRectGetHeight(frame) - 1);
UIBezierPath* fillPath = [UIBezierPath bezierPathWithRect: fillRect];
CGContextSaveGState(context);
[fillPath addClip];
CGContextRestoreGState(context);
//// TopStroke Drawing
// Do not draw top stroke unless section index is greater than 0
if (self.indexpath.section > 0) {
UIBezierPath* topStrokePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame)+1, CGRectGetWidth(frame), 1)];
[customWhite setFill];
[topStrokePath fill];
}
//// Highlight Drawing
//// BottomStroke Drawing
if (self.indexpath.row == 0) {
UIBezierPath* bottomStrokePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame) + CGRectGetHeight(frame) - 1, CGRectGetWidth(frame), 1)];
[customWhite setFill];
[bottomStrokePath fill];
}
//// Cleanup
//CGGradientRelease(gradient2);
CGColorSpaceRelease(colorSpace);
}
@end
对于TableView,方法cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MenuItemCell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Always redraw tanle cell
//if (cell == nil) {
cell = [[SideMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[(SideMenuTableViewCell *)cell setIndexpath:indexPath];
//}
cell.imageView.bounds = CGRectMake(0, 0, 10, 10);
switch (indexPath.section) {
case MMDrawerSectionAccountSection:
switch (indexPath.row) {
case 0: {
cell.imageView.image = Nil;
cell.textLabel.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:indexPath.section];
break; }
case 1: {
[cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [self.profileData valueForKey:@"firstName"], [self.profileData valueForKey:@"lastName"]]];
cell.imageView.image = [UIImage imageNamed:@"user.png"];
UILazyImageView *lazyImage = [[UILazyImageView alloc] init];
[lazyImage loadImageWithURL:[self.profileData valueForKey:@"photoURL"]];
// Resize photo profile
CGRect resizeRect;
resizeRect.size = cell.imageView.image.size;
resizeRect.origin = CGPointMake(0.0, 0.0);
UIGraphicsBeginImageContext(resizeRect.size);
[lazyImage.image drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = resizedImage;
break; }
case 2: {
[cell.textLabel setText:LOC_EN_SIDEMENU_SAVEDARTICLE];
cell.imageView.image = [UIImage imageNamed:@"saved.png"];
break; }
case 3: {
[cell.textLabel setText:LOC_EN_SIDEMENU_SAVEDHOSPITAL];
cell.imageView.image = [UIImage imageNamed:@"savedhospital.png"];
break; }
case 4: {
[cell.textLabel setText:LOC_EN_SIDEMENU_LOGOUT];
cell.imageView.image = [UIImage imageNamed:@"logout.png"];
break; }
}
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
break;
case MMDrawerSectionMenuSection:{
switch (indexPath.row) {
case 0: {
cell.imageView.image = Nil;
cell.textLabel.text = [tableView.dataSource tableView:tableView titleForHeaderInSection:indexPath.section];
break; }
case 1: {
[cell.textLabel setText:LOC_EN_SIDEMENU_NEWSFEED];
[cell.imageView setImage:[UIImage imageNamed:@"newsfeed.png"]];
break; }
case 2: {
[cell.textLabel setText:LOC_EN_SIDEMENU_ARTICLE];
cell.imageView.image = [UIImage imageNamed:@"article.png"];
break; }
case 3: {
[cell.textLabel setText:LOC_EN_SIDEMENU_HOSPITAL];
cell.imageView.image = [UIImage imageNamed:@"pinmenu"];
break; }
case 4: {
[cell.textLabel setText:LOC_EN_SIDEMENU_PURCHASE];
cell.imageView.image = [UIImage imageNamed:@"purchase"];
break; }
}
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
break;
}
default:
break;
}
return cell;
}