Pages

Showing posts with label dynamic. Show all posts
Showing posts with label dynamic. Show all posts

Saturday, August 3, 2013

Add Image from URL in UIView and make clickable

I have made a sample code for this example

Step 1 - Load Image from URL

     UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"screen.png"]];

  [self.completeSingleView addSubview:imageView];

Step 2 - Now to make this clickable just use the following code

    imageView.userInteractionEnabled = YES;
   imageView.tag = 2;

Step 3 - Now to add this in any UIView. Follow the code below

     [self.completeSingleView addSubview:imageView];

Step 4- Now to detect the Image in touch began event, follow the code below


-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    
    UITouch *touch = [touches anyObject];
    if([touch.view tag] == 2)
        NSLog(@"Your Image is Touched");
}

Monday, January 28, 2013

Work with UITabBarController dynamically


Here i have shown How to work with UITabBarController and How to add Items in It.
1. declare tabs in class ".h" file

    UITabBarController *tabs;

2. Then synthesize in ".m" file
@synthesize tabs;

3. Now Initiate this in viewLoaded and call createTabs

    tabs = [[UITabBarController alloc] init];
    [self createTabs];



- (void) createTabs
{
    UIViewController *viewController1 = [[FirstTabViewController alloc] initWithNibName:@"FirstTabViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondTabViewController alloc] initWithNibName:@"SecondTabViewController" bundle:nil];
    UIViewController *viewController3 = [[ThirdTabViewController alloc] initWithNibName:@"ThirdTabViewController" bundle:nil];
    UIViewController *viewController4 = [[FourthTabViewController alloc] initWithNibName:@"FourthTabViewController" bundle:nil];
   
    tabs.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, nil];
    
    UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"1.png"] tag:1];
    UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"2.png"] tag:2];
    UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"Third" image:[UIImage imageNamed:@"3.png"] tag:3];
    UITabBarItem *item4 = [[UITabBarItem alloc] initWithTitle:@"Logout" image:[UIImage imageNamed:@"4.png"] tag:4];
    
    [viewController1 setTabBarItem:item1];
    [viewController2 setTabBarItem:item2];
    [viewController3 setTabBarItem:item3];
    [viewController4 setTabBarItem:item4];
    [self.view addSubview:tabs.view];
}