Search This Blog

Showing posts with label Sample Code. Show all posts
Showing posts with label Sample Code. Show all posts

Sunday, August 23, 2015

How to careate a view programmatically in IOS?

UIWindow* window = [UIApplication sharedApplication].keyWindow;

UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 200, 150)];
//add code to customize, 
polygonView.backgroundColor = [UIColor blackColor];

[window addSubview:polygonView];
[polygonView release];
 
This is a pattern you will use for not only this but subviews afterwards. Also, another note is with many of the templates, the viewController is already set up with it's own view. When you want to make a custom view, you create it like above but instead of the method above you set the viewControllers view to the newly created view like so:
 
viewController.view = polygonView;
 
======================================================================== 
 
UIView *newView = [[UIView alloc] initWithFrame:mainView.bounds];
[mainView addSubview:newView];
[newView release]; 

Thursday, August 20, 2015

Create a text field, button programmatically

    UITextField *userNameField = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 300, 40)];
    userNameField.placeholder = @"userName";
    userNameField.accessibilityLabel = @"UserName Field";
    userNameField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:userNameField];
   
   
    UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(20, 90, 300, 40)];
    passwordField.placeholder = @"password";
    passwordField.secureTextEntry = YES;
    passwordField.accessibilityLabel = @"Password Field";
    passwordField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:passwordField];
   
   
    UIButton * submitButton = [UIButton buttonWithType:UIButtonTypeSystem];
    submitButton.frame = CGRectMake(20, 150, 150, 40);
    [submitButton setTitle:@"Submit" forState:UIControlStateNormal];
    submitButton.accessibilityLabel = @"Submit Button";
    [submitButton addTarget:self action:@selector(submitButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    submitButton.backgroundColor = [UIColor redColor];
    [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:submitButton];

Implementation example of button click:

-(void)submitButtonPressed:(id)Sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)loginButtonPressed:(id)sender{
    LoginViewController *loginViewController = [LoginViewController new];   // create a modal
    [self presentViewController:loginViewController animated:YES completion:nil];  // preent it as a model
}

Tell some of the KIF methods to test

waitForTappableViewWithAccessibilityLabel
waitForViewWithAccessibilityLabel

tapViewWithAccessibilityLabel

enterText:  intoViewWithAccessibilityLabel:

Examples:

    [tester waitForTappableViewWithAccessibilityLabel:@"Login Button"];
    [tester tapViewWithAccessibilityLabel:@"Login Button"];
    [tester waitForViewWithAccessibilityLabel:@"UserName Field"];
    [tester enterText:@"myUserName" intoViewWithAccessibilityLabel:@"UserName Field"];
    [tester enterText:@"myPassword" intoViewWithAccessibilityLabel:@"Password Field"];
    [tester tapViewWithAccessibilityLabel:@"Submit Button"];
   
    // Back to main view
    [tester waitForViewWithAccessibilityLabel:@"Login Button"];