有两种方式:
方式一:colorWithPatternImage
用背景颜色设置图片
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 400, 18)];
[self.view addSubview:imageView];
imageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ico_pk_bar_blue.png"]];
方式二:UIImageResizingModeTile
resize图片
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 400, 18)];
[self.view addSubview:imageView];
UIImage *image = [UIImage imageNamed:@"ico_pk_bar_blue.png"];
UIImage * newImage = [image resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
imageView.image = newImage;
网友评论