Core Graphics Vs Images for a custom button

前端 未结 2 1092
再見小時候
再見小時候 2021-02-09 17:55

When should I go with core graphics over images for making a custom UIButton? Is core graphics faster? Other than resolution independence, are there any other major benefits?

2条回答
  •  野性不改
    2021-02-09 18:11

    Additional thoughts to ughoavgfhw's comment:

    1. Images can be cached (like when you use [UIImage imageNamed:]). So you even won't use more memory for new buttons, except the first one displayed. (And no allocations, except memory for a new pointer).

    2. You can use stretchable images for button creation, and avoid some (not all and not always) problems with resolution dependence:

      UIImage *myImg = [UIImage imageNamed:@"myImg.png"];
      UIImage *myImgStretchable = [myImg stretchableImageWithLeftCapWidth:10 topCapHeight:10];
      [myButton setBackgroundImage:myImgStretchable forState:UIControlStateNormal];
      

提交回复
热议问题