我可以重新编码循环 UIImageView 以获得更短的代码吗?
我可以让这段代码比这个短吗?
- (void) setupFeature
{ NSArray *numbers = [NSArray arrayWithObjects: @"01", @"02", @"03",@"04",@"05",@"06", nil];
position = CGRectMake(7, position.origin.y+20, 72, 72);
int j=0;
NSString *pic;
UIImageView *a_pic;
NSMutableArray *C_Pic = [[[NSMutableArray alloc] init] autorelease];
for (int i=0; i<[numbers count]; i++)
{
UIImageView *picture = [[UIImageView alloc] init];
[C_Pic addObject:picture];
[picture release];
a_pic = [C_Pic objectAtIndex:i];
pic = [NSString stringWithFormat:@"iconD%@",[numbers objectAtIndex:i]];
a_pic.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:pic ofType:@"png"]];
if(j<4)
{
a_pic.frame = position;
[scrollView addSubview:a_pic];
position = CGRectMake(position.origin.x+77, position.origin.y, 72, 72);
j++;
}
else
{
j=0;
position = CGRectMake(7, position.origin.y+77, 72, 72);
NSLog(@"Pic%i position %@",i, NSStringFromCGRect(self.position));
a_pic.frame = position;
[scrollView addSubview:a_pic];
position = CGRectMake(position.origin.x+77, position.origin.y, 72, 72);
}
}
}
如果可以再短一点吗??请帮助我该怎么做?
Can I make this code shorter than this ?
- (void) setupFeature
{ NSArray *numbers = [NSArray arrayWithObjects: @"01", @"02", @"03",@"04",@"05",@"06", nil];
position = CGRectMake(7, position.origin.y+20, 72, 72);
int j=0;
NSString *pic;
UIImageView *a_pic;
NSMutableArray *C_Pic = [[[NSMutableArray alloc] init] autorelease];
for (int i=0; i<[numbers count]; i++)
{
UIImageView *picture = [[UIImageView alloc] init];
[C_Pic addObject:picture];
[picture release];
a_pic = [C_Pic objectAtIndex:i];
pic = [NSString stringWithFormat:@"iconD%@",[numbers objectAtIndex:i]];
a_pic.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:pic ofType:@"png"]];
if(j<4)
{
a_pic.frame = position;
[scrollView addSubview:a_pic];
position = CGRectMake(position.origin.x+77, position.origin.y, 72, 72);
j++;
}
else
{
j=0;
position = CGRectMake(7, position.origin.y+77, 72, 72);
NSLog(@"Pic%i position %@",i, NSStringFromCGRect(self.position));
a_pic.frame = position;
[scrollView addSubview:a_pic];
position = CGRectMake(position.origin.x+77, position.origin.y, 72, 72);
}
}
}
If it can be shorter ?? please , help me how to do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以更短,看看这个
Yes it can be shorter see this