----------UI窗口于視圖的創(chuàng)建示例----------
在北票等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都網站設計、網站制作 網站設計制作按需求定制網站,公司網站建設,企業(yè)網站建設,成都品牌網站建設,全網營銷推廣,成都外貿網站建設公司,北票網站建設費用合理。在window上創(chuàng)建赤橙黃綠青藍紫七個視圖,互相嵌套,設置定時器,每秒每個視圖隨機變換顏色,并且旋轉,十秒后停止,視圖全部移除。
---AppDelegate.h中聲明視圖和一個計時的變量
@interface AppDelegate : UIResponder
{
UIView *view1;
UIView *view2;
UIView *view3;
UIView *view4;
UIView *view5;
UIView *view6;
UIView *view7;
int second;
}
---AppDelegate.m中實現題中要求
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect rect = [UIScreen mainScreen].bounds;
//創(chuàng)建主Window
self.window = [[UIWindow alloc]initWithFrame:rect];
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
//創(chuàng)建View
view1 = [[UIView alloc]initWithFrame:CGRectMake(70, 70, 250, 250)];
view1.backgroundColor= [UIColor redColor];
view1.tag = 1;
view2 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 220, 220)];
view2.backgroundColor= [UIColor orangeColor];
view3 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 190, 190)];
view3.backgroundColor= [UIColor yellowColor];
view4 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 160, 160)];
view4.backgroundColor= [UIColor greenColor];
view5 = [[UIView alloc]initWithFrame:CGRectMake(15, 15 , 130, 130)];
view5.backgroundColor= [UIColor cyanColor];
view6 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 100, 100)];
view6.backgroundColor= [UIColor blueColor];
view7 = [[UIView alloc]initWithFrame:CGRectMake(25, 25, 50, 50)];
view7.backgroundColor= [UIColor purpleColor];
[self.window addSubview:view1];
[view1 addSubview:view2];
[view2 addSubview:view3];
[view3 addSubview:view4];
[view4 addSubview:view5];
[view5 addSubview:view6];
[view6 addSubview:view7];
second = 10;
//定時器
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(timeAction:)
userInfo:nil
repeats:YES];
return YES;
}
- (void)timeAction:(NSTimer *)timer{
//七個視圖顏色隨機變
view1.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view2.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view3.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view4.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view5.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view6.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
view7.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];
//旋轉
UIView *view = [self.window viewWithTag:1];
CGAffineTransform trans = view.transform;
view.transform = CGAffineTransformRotate(trans, M_PI/10);
//十秒后計時器停止,視圖移除
second--;
if (second < 0) {
[timer invalidate];
[view1 removeFromSuperview];
return;
}
}
創(chuàng)新互聯www.cdcxhl.cn,專業(yè)提供香港、美國云服務器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網絡助力業(yè)務部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統配攻擊溯源,準確進行流量調度,確保服務器高可用性。佳節(jié)活動現已開啟,新人活動云服務器買多久送多久。