开发者

iPhone Changing Labels

开发者 https://www.devze.com 2022-12-19 19:29 出处:网络
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

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

精彩评论

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

关注公众号