iOS应用性能调优的25个建议和技巧(17)

    xiaoxiao2021-11-30  55

    17. 正确设定背景图片

    View里放背景图片就像很多其它iOS编程一样有很多方法:

    1      使用UIColor colorWithPatternImage来设置背景色;

    2      view中添加一个UIImageView作为一个子View

    如果你使用全画幅的背景图,你就必须使用UIImageView因为UIColorcolorWithPatternImage是用来创建小的重复的图片作为背景的。这种情形下使用UIImageView可以节约不少的内存:

    1

    2

    3

    // You could also achieve the same result in Interface Builder

    UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];

    [self.view addSubview:backgroundView];

     

    如果你用小图平铺来创建背景,你就需要用UIColorcolorWithPatternImage来做了,它会更快地渲染也不会花费很多内存:

    1

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];

     

    转载请注明原文地址: https://ju.6miu.com/read-679159.html

    最新回复(0)