Thursday, 15 January 2015

ios - why do my UILabels not appear in the right spaces -



ios - why do my UILabels not appear in the right spaces -

i have game. loading 3 image views label objects. load 5, , 7. yesterday had same issue, , found reply making autoresizing mask on labels none. well, did that, fixed it, issue today. confusing, , have no clue how prepare it.

my question is, why still happening if i've done that? , how can prepare it?

here code:

// random word array of object nsstring *randomword = [self.objects objectatindex:randomobject]; [self.imageviews[i] addsubview:self.labels[i]]; [self.labels[i] setcenter:[self.imageviews[i] center]]; // labels setting text , alignment [self.labels[i] settext:randomword]; [self.labels[i] settextalignment:nstextalignmentcenter]; // adding words alphabetical array [self.alphabeticalwords addobject:randomword]; nslog(@"%@", randomword); //nslog(@"%@", self.alphabeticalwords); [self.labels[i] sizetofit]; [self.labels[i] setautoresizingmask:uiviewautoresizingnone]; [self.imageviews[i] setuserinteractionenabled:yes]; [self.imageviews[i] addgesturerecognizer:pangesture];

and here issue

any help much appreciated.

one issue utilize if view hierarchy , center. adding labels subviews image views , using center seek overlay them. definition of center is:

the center specified within coordinate scheme of superview , measured in points. setting property changes values of frame properties accordingly.

setting center of subview center of superview not behave way want because not sitting in same coordinate space.

you should using bounds of image view represents internal coordinate space. want instead:

[self.labels[i] setcenter:cgpointmake((self.imageviews[i].bounds.size.width / 2), (self.imageviews[i].bounds.size.height / 2)];

ios objective-c uiimageview uilabel

No comments:

Post a Comment