开发者

iPhone Changing Labels

How would I go about having a list of labels, and when a Round Rectangular Butt开发者_如何学Goon is pushed the UILabel above it changes to a label off the list randomly.


Assuming you've already setup your labels and defined an index to the current label in your interface, you could do something like this:

NSArray *labels = [NSArray arrayWithObjects:label1, label2, label3, nil];
int currentLabel = 0;

-(void)onButtonPress:(id)sender {
    [[labels objectAtIndex:currentLabel++] removeFromSuperview];
    if (currentLabel == [labels count])
        currentLabel = 0;
    [self addSubview:[labels objectAtIndex:currentLabel]];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜