How do I create a CGRect from a CGPoint and CGSize?

后端 未结 4 436
攒了一身酷
攒了一身酷 2021-02-01 01:22

I need to create a frame for a UIImageView from a varying collection of CGSize and CGPoint, both values will always be different depending

4条回答
  •  北海茫月
    2021-02-01 01:45

    you can use some sugar syntax. For example:

    This is something like construction block you can use for more readable code:

    CGRect rect = ({
       CGRect customCreationRect
    
       //make some calculations for each dimention
       customCreationRect.origin.x = CGRectGetMidX(yourFrame);
       customCreationRect.origin.y = CGRectGetMaxY(someOtherFrame);
    
       customCreationRect.size.width = CGRectGetHeight(yetAnotherFrame);
       customCreationRect.size.height = 400;
    
       //By just me some variable in the end this line will
       //be assigned to the rect va
       customCreationRect;
    )}
    

提交回复
热议问题