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

iOS中的UIView的基本属性1

2015-08-27 22:24 666 查看
@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//UIweindow 应用程序的窗口,用于将内容展示给用户
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
//创建view
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 90, 100, 100)];
//设置背景颜色
redView.backgroundColor=[UIColor redColor];

//添加到父控件
[self.window addSubview:redView];

//一个视图只有一个父视图
UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(50,200, 100,100)];

UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(56,200, 100,100)];
[self.window addSubview:greenView];

greenView.backgroundColor = [UIColor greenColor];
grayView.backgroundColor = [UIColor grayColor];

[redView addSubview:grayView];
[self.window addSubview:grayView];

//释放内存
[redView release];
[grayView release];
[greenView release];

//UIView的重要属性
//1.backgroundColor 背景颜色
//2.hidden 显隐性 //控制视图的显隐性,默认为NO
//3.alpha 透明度,控制视图的透明度,取值范围0.0 - 1.0
//4.superview 获得父视图
//5.subvievs 获得子视图,使用数组进行管理,子视图的添加是有序的,添加顺序对应上数组元素的位置
//6.tag 标签,唯一标示指定视图
[self.window viewWithTag:250];

//通过字视图也可以获得 子
//UIView *lase = [self.window subviews].lastObject;

// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

//设置Window的背景颜色
//让UIwindow成为程序的主窗口,并且可视
//[self.window makeKeyAndVisible];

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