先来展示一下效果:
这两张图片主要是先静止,没有小猫,后来2秒钟之后,有小猫出现,还有它说的话(如果你愿意这么样设定的话)然后按住button实现说话的内容消失,只有小猫。
首先,没有图片的时候,是一个rootview
然后等2秒 需要用到nstimer
之后小猫出现还有它说的话,她说的话要做成另外一个view view上面不能写字,只能自己设定一个label 显示静态的字符,在label上面设置字体的大小和样式,最后设定button,对button的事件进行方法实现。代码如下:
@interface RootViewController ()
{
UIView*bland;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:@selector(Change:) withObject:self afterDelay:2];
// Do any additional setup after loading the view.
}
-(void)Change:(id)sender
{
UIColor* viewMao=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"mao.jpg"]];
[self.view setBackgroundColor:viewMao];
bland=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[bland setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:bland];
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[label setBackgroundColor:[UIColor whiteColor]];
label.text=@"我知道你已经喂过猫咪了,可我是企鹅啊";
label.font=[UIFont fontWithName:nil size:10];
[bland addSubview:label];
UIButton*button=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame=CGRectMake(290, 10, 30, 30);
[bland addSubview:button];
[button addTarget:self action:@selector(doClose) forControlEvents:UIControlEventTouchDown];
//[button addTarget:self action:@selector(Disppear) forControlEvents:UIControlEventTouchDown];
}
-(void)doClose
{
[bland removeFromSuperview];
}