我怎么能直接在UIView上设置Image?

Shi*_*lpa 17 iphone uiimageview addsubview

任何人都可以告诉我如何直接设置Image UIView?这是我的代码:

 UIView *view=[[UIView alloc]init];
 [view setImage:[UIImage imageNamed:@"image.png"]];
Run Code Online (Sandbox Code Playgroud)

小智 21

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"a.png"]]];
Run Code Online (Sandbox Code Playgroud)

希望这对你有所帮助.


msg*_*bel 11

这很简单.尝试:

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];
Run Code Online (Sandbox Code Playgroud)

你也可以用玩UIImageView框架属性它四处移动你的UIView.希望有帮助!