UIImageView的属性与方法
来源:互联网 发布:祝利荣牛熊线指标源码 编辑:程序博客网 时间:2024/05/16 19:09
bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle。
获取图片
1. NSString *path = [[NSBuddle mainBuddle] pathForResource:@"resourceName" oftype@"resourceType"];
UIImage *image = [UIImage imageWithContentsOfFile:path]
]; //使用缓存,一般用小图片
2. UIImage *image = [UIImage imageNamed:@"imageName"];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
iv = [[UIImageViewalloc]initWithFrame:CGRectMake(30,100, 62,74)];
//uiimage 直接使用类的方法UIImage imageNamed用到了缓存
// UIImage * ig = [UIImage imageNamed:@"nc.png"];
self.window.backgroundColor=[UIColorwhiteColor];
//得到图片nc.png的路径
NSString *path = [[NSBundlemainBundle]pathForResource:@"nc"ofType:@"png"];
//UIImage imageWithContentsOfFile从路径中得到图片传给ig
ig = [UIImageimageWithContentsOfFile:path];
NSLog(@"%@",path);
//把image挂在imageview上
[ivsetImage:ig];
UIButton * but = [[UIButtonalloc]initWithFrame:CGRectMake(130,110, 50,40)];
[but setTitle:@"转换"forState:UIControlStateNormal];
but.backgroundColor=[UIColorblueColor];
[but addTarget:selfaction:@selector(ac)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:but];
[self.windowaddSubview:iv];
[self.windowmakeKeyAndVisible];
returnYES;
}
-(void)ac
{
if (flag==NO) {
ig=[UIImageimageNamed:@"nc.png"];
[ivsetImage:ig];
flag=YES;
}
else
{
ig=[UIImageimageNamed:@"zd.png"];
[ivsetImage:ig];
flag=NO;
}
}
- UIImageView的属性与方法
- iOS学习笔记------UIButton、UIImageView、UILabel的属性与方法
- UIImageView 属性 方法
- UIImageview的contentMode属性
- UIImageView 的contentMode属性
- UIImageView的contentMode属性
- UIImageView的一些属性
- UIImageView 的contentMode属性
- UIImageView 的contentMode属性
- UIImageView的属性
- UIImageView 的contentMode属性
- UIImageView的ContentMode属性
- UIImageView 的contentMode属性
- UIImageView 的contentMode属性
- UIImageView 的contentMode属性
- UIImageVIew的各个属性
- UIImageView常用属性和方法
- UIImageView 的contentMode属性应用
- 九度OJ-题目1001:A+B for Matrices
- iOS XML解析
- iOS高效编程秘诀—坚持编程习惯
- 应用内存优化之OnLowMemory&OnTrimMemory
- 面试题 多线程安全队列的实现(改进版)
- UIImageView的属性与方法
- 使用ViewPager加载Fragment
- MvvmLight(四)消息通知Messenger
- 虚基类与虚继承
- iOS-浅谈runtime运行时机制02-runtime简单使用
- 在Ubuntu(Linux)上安装Android Studio
- Linux C语言程序设计(十六)——TCP/IP协议基本解析
- reaver-wps
- PowerDesigner中物理模型添加外键