UIImageView change Width and Height

后端 未结 8 789
-上瘾入骨i
-上瘾入骨i 2021-02-13 10:12

I\'ve read various posts on here asking similar questions... I\'ve tried various ways that were posted including bounds and frames etc. including the following:



        
8条回答
  •  旧巷少年郎
    2021-02-13 10:55

    From what I get of the question, the OP wanted to change the size of the UIImageView when the size of the container UIView is changed. The code below will do it...

    UIView * foo = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)] autorelease];
    foo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    UIImageView * bar = [[UIImageView alloc] initWithImage:
                         [UIImage imageNamed:@"test.png"]];
    bar.autoresizingMask = foo.autoresizingMask;
    [foo addSubview:bar];
    [self.view addSubview:foo];
    

    The key here are the foo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight and the bar.autoresizingMask = foo.autoresizingMask; lines. Forget either of these, and the whole jigmarole will stop working.

提交回复
热议问题