您的位置:首页 > 产品设计 > UI/UE

iOS UIImageView的简单使用

2013-11-03 09:59 369 查看
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

UIImageView *pImageView=[[UIImageView alloc]initWithFrame:CGRectMake(20, 110, 280,200 )];
pImageView.image=[UIImage imageNamed:@"p3"];
pImageView.tag=100;
//是否高亮
//    pImageView.highlighted=YES;
//当添加按钮时 必须YES
pImageView.userInteractionEnabled=YES;
//背景色
pImageView.backgroundColor=[UIColor redColor];
//高亮时的图片
pImageView.highlightedImage=[UIImage imageNamed:@"p4.png"];
//添加视图
[self.window addSubview:pImageView];

//创建Button 将它添加在imageView上
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(105, 80, 70, 40);
[btn setTitle:@"start" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(changeShow:) forControlEvents:UIControlEventTouchUpInside];
//将按钮添加到 UIImageView 上
//添加按钮则   pImageView.userInteractionEnabled=YES; 必须写上
[pImageView addSubview:btn];

return YES;
}

-(void)changeShow:(id)sender
{
static BOOL num=YES;
//获取 UIImageView
UIImageView *pImageView=(UIImageView *)[self.window viewWithTag:100];
if (num) {
pImageView.highlighted=YES;
num=NO;
}
else
{
pImageView.highlighted=NO;
num=YES;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: