我正在研究这个for循环并且它工作得很完美..我经常返回找到的数字列表,但是我需要for循环让我按降序返回数字...从30到18而不是现在18-30岁......有人可以帮我一个忙吗?
我发布了有问题的代码
for (NSInteger i = 18; i <= 30; i += 2) {
self.axisY_Label = [[UILabel alloc] initWithFrame:CGRectMake(10, paddingValue, 35, 20)];
self.axisY_Label.text = [NSString stringWithFormat:@"%ld", (long)i];
self.axisY_Label.textColor = [UIColor whiteColor];
self.axisY_Label.font = [UIFont fontWithName:@"HelveticaNeue" size:13];
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(_axisY_Label.frame.size.width, _axisY_Label.center.y, self.frame.size.width, 0.3)];
line.backgroundColor = [UIColor whiteColor];
line.alpha = .2;
[self addSubview:line];
paddingValue += _axisY_Label.frame.size.width;
[self addSubview:_axisY_Label];
}
答案 0 :(得分:1)
交换from
和to
参数并向后计数
for (NSInteger i = 30; i >= 18; i -= 2) { ...