ios - randomly distributing labels in a view -
I am trying to distribute many labels on a view randomly. The code works below but clearly the distribution is not very random, so I have replaced this line in
cat.frame = CGRectMake (self.view.frame.size.width - ( 50 * arc4random ()% Self.numOfCats), (50 * arc4random ()% self.numOfCats), 100, 100); To try to make a few thumbnails of at least randomity, however, can you explain any labels on the screen and there was no error message?
Bonus I do not think that the method of making randomness is that the great (i.e., never expected to get 0,0), bonuses, improve your method Can you also make randomness? I have to make sure that no label is being overlapping ... for (int i = 1; i & lt; = self.numOfCats; i ++) {cat * Cat = [self timer]; Cat.frame = CGRectMake (self.view.frame.size.width - 500, 100 * i, 100, 100); [self.view addSubview: cat]; } This should know about the better view of your random status Labels:
cgttefram = cat.frame; // The original frame, which was considering the size / / to avoid it on the outside of the screen, consider the width of the cat newframe.origin.x = [Self randomplitbetliner limit: 0 upper limit: CGRactivetwidth (self. View .frame) - cgreframe (cat.frame)]; // Keep it out of screen newFrame.origin.y = Consider the width of the cat [self randomFloatBetweenLowerLimit: 0 UPPERLIMIT: CGRectGetHeight (self.view.frame) - CGRectGetHeight (cat.frame)]; Cat.frame = newFrame; This will be the way to consider the relative bias to get a random boat:
- randomFloatBetweenLowerLimit: (CGFloat) LOWERLIMIT UPPERLIMIT: (CGFloat) Upper limit {return arc4random_uniform (UINT32_MAX) / (CGFloat) UINT32_MAX * (upper limit - lower limit) + less limit; }
Comments
Post a Comment