Cocoa Touch - Adding a UIImageView programmatically?

Viewed 49016

How can I create and position a new imageview in objective-c?

Thanks!

I tried this but it doesnt seem to do anything...

-(void)drawStars{ //uses random numbers to display a star on screen
    //create random position
    int xCoordinate = arc4random() % 10;
    int yCoordinate = arc4random() % 10;

    UIImageView *starImgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, 58, 40)]; //create ImageView 

    starImgView.image = [UIImage imageNamed:@"star.png"];


    [starImgView release];

I placed this method in my viewcontroller. I see some CG stuff do I need to import core graphics or something? (what is core graphics anyway?)

4 Answers
Related