UIImageView的属性与方法
2015-09-04 13:23
453 查看
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 = [[UIWindow
alloc]initWithFrame:[[UIScreen
mainScreen]bounds]];
iv = [[UIImageView
alloc]initWithFrame:CGRectMake(30,
100, 62,
74)];
//uiimage 直接使用类的方法UIImage imageNamed用到了缓存
// UIImage * ig = [UIImage imageNamed:@"nc.png"];
self.window.backgroundColor=[UIColor
whiteColor];
//得到图片nc.png的路径
NSString *path = [[NSBundle
mainBundle]pathForResource:@"nc"
ofType:@"png"];
//UIImage imageWithContentsOfFile
从路径中得到图片传给ig
ig = [UIImage
imageWithContentsOfFile:path];
NSLog(@"%@",path);
//把image挂在imageview上
[iv
setImage:ig];
UIButton * but = [[UIButton
alloc]initWithFrame:CGRectMake(130,
110, 50,
40)];
[but setTitle:@"转换"
forState:UIControlStateNormal];
but.backgroundColor=[UIColor
blueColor];
[but addTarget:self
action:@selector(ac)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:but];
[self.window
addSubview:iv];
[self.window
makeKeyAndVisible];
return
YES;
}
-(void)ac
{
if (flag==NO) {
ig=[UIImage
imageNamed:@"nc.png"];
[iv
setImage:ig];
flag=YES;
}
else
{
ig=[UIImage
imageNamed:@"zd.png"];
[iv
setImage:ig];
flag=NO;
}
}
我们把这个目录叫做程序的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 = [[UIWindow
alloc]initWithFrame:[[UIScreen
mainScreen]bounds]];
iv = [[UIImageView
alloc]initWithFrame:CGRectMake(30,
100, 62,
74)];
//uiimage 直接使用类的方法UIImage imageNamed用到了缓存
// UIImage * ig = [UIImage imageNamed:@"nc.png"];
self.window.backgroundColor=[UIColor
whiteColor];
//得到图片nc.png的路径
NSString *path = [[NSBundle
mainBundle]pathForResource:@"nc"
ofType:@"png"];
//UIImage imageWithContentsOfFile
从路径中得到图片传给ig
ig = [UIImage
imageWithContentsOfFile:path];
NSLog(@"%@",path);
//把image挂在imageview上
[iv
setImage:ig];
UIButton * but = [[UIButton
alloc]initWithFrame:CGRectMake(130,
110, 50,
40)];
[but setTitle:@"转换"
forState:UIControlStateNormal];
but.backgroundColor=[UIColor
blueColor];
[but addTarget:self
action:@selector(ac)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:but];
[self.window
addSubview:iv];
[self.window
makeKeyAndVisible];
return
YES;
}
-(void)ac
{
if (flag==NO) {
ig=[UIImage
imageNamed:@"nc.png"];
[iv
setImage:ig];
flag=YES;
}
else
{
ig=[UIImage
imageNamed:@"zd.png"];
[iv
setImage:ig];
flag=NO;
}
}
相关文章推荐
- 文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3
- 文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3
- InnoDB: The log sequence number in ibdata files does not match
- iOS ui界面vtf 开发
- UIday0801:UINavigationController视图控制器的属性和用法
- UI:登录窗的自定义键盘
- arduino与Processing通信问题
- UISearchBar 修改占位符的放大镜
- QuickNews新闻客户端源码
- HDU 1242 Rescue - DFS 回溯
- iOS开发之有趣的UI —— UIScrollerView 控件及案例
- Nqueen1.0
- QSqlQueryModel使用小结
- UIButtont特殊样式
- UILabe的特殊格式
- UIView
- UITextField
- UIImageView以及动画
- Android Studio创建module缺少build文件夹
- String,StringBuffer与StringBuilder的区别??