Tiled Background Image: Can I do that easily with UIImageView?

前端 未结 7 1083
甜味超标
甜味超标 2020-12-07 13:05

I have a fullscreen background image that is tiled, i.e. it has to be reproduced a few times horizontally and vertically in order to make a big one. Like in the browsers on

相关标签:
7条回答
  • 2020-12-07 14:04

    As I really like Interface Builder I created this UIImageView subclass to apply tiled backgrounds:

    @interface PETiledImageView : UIImageView
    
    @end
    
    @implementation PETiledImageView
    
    - (void)awakeFromNib
    {
        [super awakeFromNib];
    
        UIImage * imageToTile = self.image;
        self.image = nil;
        UIColor * tiledColor = [UIColor colorWithPatternImage:imageToTile];
        self.backgroundColor = tiledColor;
    }
    
    @end
    

    I tried overriding setImage: but it seems IB doesn't call it when decoding a Nib file.

    0 讨论(0)
提交回复
热议问题