What does the addSubview method look like?

流过昼夜 提交于 2019-12-11 16:10:33

问题


I'm aware of it's function and how to use the addSubview method.

What would like to know is what the method looks like, the code used in that method it self.. and if someone could point me to the right direction in finding this out for my self next time.

I assume I could find it in the Developer Documentation, and I found the method, and what it does (which I already know) but I'd like to see sample code, if possible. Thanks =]


回答1:


The implementation code is not publicly available, iOS is not open source. The closest you can get is the header file but that only declares the interface, which doesn't give you anything you can't get from the documentation.




回答2:


Here is a simple example using the AppDelegate class from the "Empty Application" new project template:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // create label to add to UIView
    UILabel * label1 = [[UILabel] alloc] initWithFrame:CGRectMake(20, 20, 280, 100)];
    label1.text = @"Hello World";

    // create view to add to UIWindow
    UIView * view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    [view1 addSubview:label1];
    [label1 release];

    // create window to display
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    [self.window addSubview:view1];
    [self.window makeKeyAndVisible];
    [view1  release];

    return(YES);
}


来源:https://stackoverflow.com/questions/8543642/what-does-the-addsubview-method-look-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!