UICollectionView  应该可以实现
当然自己计算位置来实现一样可以来做。最底层的那个框直接切成一个图片,只需要关心上层icon及title的位置。可以定义一个model类来封装一下

解决方案 »

  1.   


    我基本可以实现了,但是怎样让里面的格子完美居中?就像一个文本框可以设置center一样。
    http://www.cocoachina.com/bbs/read.php?tid=168709
      

  2.   

    我下面说的方案不是基于UICollectionView来实现的。
    每一个方格,你可以自定义一个控件,这个控件名定义为CustomCell ,这个cell接收一个实体model,包含icon及title的实体
    @interface CellModel : NSObject
    @property (nonatomic,strong) NSString *iconName;
    @property (nonatomic,strong) NSString *title;
    @end@class CellModel;
    @interface CustomCell: UIView
    @property (nonatomic,strong) CellModel *model;-(id)initWithModel:(CellModel *)cm;@end
    #import "CellModel.h"
    @implement CustomCell-(id)initWithModel:(CellModel *)cm {
          if (self=[super init]) {
               self.model=cm;
          }      return self;
    }-(void)layoutSubview {
         
          if (nil!=self.model) {
               /////draw icon          CGRect bounds=self.bounds;
               UIImage *iconImg=[UIImage imageNamed:self.model.iconName];           UIImageView *iconView=[[UIImageView alloc] initWithImage:iconImg];
               /////compute position. set iconview's frame
               iconView.frame=CGRectMake((bounds.width-iconImg.size.width)/2, 5, iconImg.size.width,iconImage.size.height);
               [self addSubview:iconView];           //////draw title
               UILabel *lblTitle=[[UILabel alloc] init];
               [lblTitle setTitle:self.model.title];
               [lblTitle setColor;[UIColor black]];
               [lblTitle setFont: [UIFont fontWithsize:12]];
               [lblTitle setNumberOfLines:0];
               [lblTitle setLineBreakModel:NSLineBreakWordWarpping];           CGSize titleSize=[lblTitle.text sizeWithFont:lblTitle.font];           lblTitle.frame=CGRectMake((bounds.width-titleSize.width)/2, CGRectGetMaxY(iconView.frame)+5, titleSize.width,titleSize.height);
               [self addSubview:lblTitle];      }
    }@end上面只是部分伪代码,纯手写,不保证完全正确。大体的思路应该是这样。
      

  3.   

    手写这么多,辛苦了。今天起床突然一开窍,发觉这个问题其实挺容易的。首先先把cell宽度定好了。cell直接没有空隙,这样所有的cell都平均的横向分布。然后再把里面的图片居中就好了。如下图所示:哥那么厉害有空再回答我个问题吧。请教类似日历类似效果的实现  http://www.cocoachina.com/bbs/read.php?tid=168789