有没有人能告诉我如何直接在UIView
上设置图片?这是我的代码:
UIView *view=[[UIView alloc]init];
[view setImage:[UIImage imageNamed:@"image.png"]];
有没有人能告诉我如何直接在UIView
上设置图片?这是我的代码:
UIView *view=[[UIView alloc]init];
[view setImage:[UIImage imageNamed:@"image.png"]];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"a.png"]]];
希望这能帮到你。这很简单。尝试:
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(origin_x, origin_y, width, height)];
UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a.png"]];
[view addSubview:imageView];
[imageView release];
你还可以操作 UIImageView
的 frame 属性,将其在 UIView
中移动。希望这有所帮助! UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[imageView setImage:[UIImage imageNamed:@"320_480clouds_background.png"]];
self.tableView.backgroundView = imageView;
[imageView release];
Swift版本:
let view = UIView(frame: CGRectMake(0, 0, 640, 200))
view.backgroundColor = UIColor(patternImage: UIImage(named: "myImage")!)
Swift 3:
let view = UIView(frame: CGRect(x: 0, y: 0, width: 640, height: 200))
view.backgroundColor = UIColor(patternImage: UIImage(named: "myImage")!)
UIView *aView=[[UIView alloc]init];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"anImage.png"]];
aView.backgroundColor = background;
[background release];
我在这里将CGImage分配给图层的contents属性,该属性接受CGImage或NSImage。您只能将CGImage或NSImage分配到contents属性。
layerView.layer.contents = UIImage(named: "Mario.png")?.cgImage