0

I have a custom UIImageView where i am placing a UILabel in the init method:

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, (self.frame.size.width - 14), (self.frame.size.height - 14))];
        self.displayNameLabel.center = CGPointMake((self.frame.size.width / 2), (self.frame.size.height / 2));
        self.displayNameLabel.backgroundColor = [UIColor clearColor];
        self.displayNameLabel.textAlignment = UITextAlignmentCenter;
        self.displayNameLabel.font = [UIFont fontWithName:labelFont size:22];
        [self addSubview:self.displayNameLabel];

        // Other code
    }
}

this is placed in another UIImageView which is in a UIScrollView.

so, UIScrollView which contains UIImageView which contains custom UIImageView which contains UILabel

when i zoom in on the UIScrollView, my label gets all goofy.

how it looks with no zoom:

enter image description here

after zooming in:

enter image description here

I do resize the custom UIImageView when i zoom in so it keeps a constant size (doesn't get larger as you zoom in):

-(void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    for (PointImageView *point in self.mapImageView.subviews)
    {
        if ([point isKindOfClass:[PointImageView class]])
        {
            CGPoint oldCenter = point.center;

            float pointSize = point.frame.size.width;

            float newPointSize = pointSize / zoomScale;

            point.frame = CGRectMake(point.frame.origin.x, point.frame.origin.y, newPointSize, newPointSize);

            point.center = oldCenter;
        }
    }

    oldZoomScale = scrollView.zoomScale;
}

when i move my custom UIImageView, why doesn't the label move with it?

4

1 回答 1

0

好吧,你不是在移动,而是在缩放,所以这是不同的。您还需要调整 uilabel 框架并将 uilabel 行数设置为 1 并将 adjustsfontsizetofitwidth 设置为 yes。还将 minimumFontSize 设置为 5 或 6 像素。

于 2012-10-12T21:01:29.373 回答