开发者

How to shuffle button or title over button?

I have 'n' button. I want to shuffle those button in my application. Or you can say that i want to shuffle the title over buttons. Is it p开发者_开发问答ossible.Its an Iphone app.


What you might need to know:

  • How to change the position of a button. You can do this with frame property. If you change just the origin member of CGRect, you can move the button without resizing it.
  • How to change the title of a button (if you don't want to change its position). This can be achieved with the setTitle:forState: method of UIButton.
  • Determining a random number. For general-purpose random number generation, you can use the rand() method. For more serious random number generation there are other methods available but rand() should suffice for your needs. Just ensure to call srand() with some seed before your first call to rand().
  • If you have 100 buttons, you probably should not use Interface Builder but you should create the buttons separately, otherwise you will end up with a class with 100 IBOutlet variables. Creating them yourself and maintaining them in an array will give you greater control over their shuffling. Creating them manually has been discussed on StackOverflow previously.


Of course it's possible. You can swap titles on two buttons like this:

UIButton *b1, *b2;
NSString *tmp;
tmp = [b1 text];
[b1 setText:[b2 text]];
[b2 setText:tmp];

You can extend this procedure to n buttons.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜