UIImageView:可以通过UIImage加载图片赋给UIImageView,加载后你可以指定显示的位置和大小。 1、初始化
2012-09-04 21:37
489 查看
UIImageView*imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(0.0,45.0,300,300)];
imageView.image=[UIImageimageNamed:@"a.png"];//加载入图片
[self.viewaddSubView:image];
[imageViewrelease];
//imageNamed方法是不能通过路径进行加载图片的,此方式容易引起发生内存警告从而导致自动退出的问题。
//最好是通过直接读取文件路径[UIImageimageWithContentsOfFile]解决掉这个问题.
NSImage*image=[[NSImagealloc]initWithContentsOfURL:(NSURL*)];
NSImage*image=[[NSImagealloc]initWithContentsOfFile:(NSString*)];
如:
1、》》》
UIImage*image=[[UIImagealloc]initWithData:[NSDatadataWithContentsOfURL:[NSURLURLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView*imageView=[[UIImageViewalloc]initWithImage:image];
2、》》》
NSString*path=[[NSBundlemainBundle]pathForResource:@”icon”ofType:@”png”];
NSImage*myImage=[UIImageimageWithContentsOfFile:path];
//让一个UIImageView响应点击事件
UIImageView*imgView=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,320,44)];
imgView.userInteractionEnabled=YES;
UITapGestureRecognizer*singleTap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(onClickImage)];
[imgViewaddGestureRecognizer:singleTap];
[singleTaprelease];
-(void)onClickImage{
//here,dowhateveryouwanttodo
NSLog(@"imageviewisclicked!");
}
相关文章推荐
- android 通过uri截取指定大小的图片显示在imageview上
- 带有侧滑菜单的+ 通过retrofit获取数据,通过fresco框架加载图片,使用TabLayout + ViewPage + Fragment + ListView 显示数据
- Android中【下拉刷新/上拉加载】WebView网页控件,Snackbar+CoordinatorLayoutt提示框(指定位置显示的提示框)
- xUtils 获取网络数据 + RecycleView 显示数据+ F resco 加载图片 + ButterKnife 初始化控件
- ios开发 button或UIimageview加载图片显示颜色不显示图片
- TextView加图片,真正可以调大小位置
- uiimageview设置contentMode为ScaleAspectFill后显示的不是view的大小而是图片的大小了
- 给iOS项目中添加图片,并通过UIImageView引用和显示该UIImage图片
- iOS UIImageView 网络加载图片自适应大小问题
- 加载图片显示时的图片变形问题(UIImageView)
- android TextView如何通过setCompoundDrawables调整文字和图片的位置(文字显示在图片内)?
- HorizontalScrollview显示指定位置
- IOS-UIImageView 图片自适应大小
- Android ImageView设置图片的可见性,设置颜色的不同方法,设置图片指定大小
- c# 添加图片水印,可以指定水印位置+生成缩略图
- uiimageView 中图片显示问题
- 37-002-1 通过spring的OpenSessionInViewFilter解决jsp页面懒加载显示的问题
- Swift中tableView加载通过xib创建的headerView时,无法显示xib视图内容.
- webkit显示未加载到的图片时,如何自定义指定该图片,或者屏蔽该显示
- 修改UITableViewCell中UIImageView的位置和大小