目标c-如何在iphone中以缩略图形式显示阵列图像



我是手机编程的新手。

有人能告诉我如何像照片库一样在4by4缩略图中显示文档目录文件夹图像吗?所有图像都存储在一个阵列中。

试试这个,

->您必须添加滚动视图,然后连接IBOutlet

- (void)viewDidLoad
{
    [super viewDidLoad];
int nLastYPos = 0;
 for (int i=0; i<[arrImages count]; i++)
    {
        UIView *Viewthumbnail = [[UIView alloc] init];
        Viewthumbnail.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[NSString StringByAppendingFormat:@"%@",[arrImages objectAtIndex:i]]]];
        Viewthumbnail.frame = CGRectMake(4+(i%4)*44,5+(i/4)*44, 42, 42);
        [scroll addSubview: Viewthumbnail];
        nLastYPos = btnthumbnail.frame.origin.y+44;
        [Viewthumbnail release];
    }
    if(nLastYPos>280)
        scroll.contentSize = CGSizeMake(scroll.frame.size.width,nLastYPos);
}

您可以创建宽度和高度为u的子视图,然后将其添加到superview"scrollView"中

-(void) createGridView:(NSMutilbeArray *)array{
for(int i=0;i<array.count;i++)
{
  UIView *temp=[[UIView alloc] initWithFrame:CGRectMake(x,y,wi,hi)];//UIImageView
  [scrollView addSubView:temp];
}
}

u可以通过sender.tag 为每个视图标记提供触摸操作

最新更新