UIImageView change Width and Height

后端 未结 8 788
-上瘾入骨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 11:05

    If you tried those methods cannot work, the only way to do it is to add the constraint of width and height to the UIImageView.

    // Create the constraint in code
    NSLayoutConstraint *constraint0 = [NSLayoutConstraint constraintWithItem: myImage attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1.0f constant: yourNewsWidth];
    
    
    NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem: myImage attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0f constant: yourNewsHeight];
    
    [myImage addConstraint:constraint0];
    [myImage addConstraint:constraint1];
    

提交回复
热议问题