addSubview does not show view on iOS 3.1.3 - iphone

I have a scroll view which has one UIView inside which contains the content. I am adding a UIImageView as a sub of the UIScrollView (so it should be on top of the content container) and this works on iPhone 3.2+, but on an iPhone running 3.1.3 the image does not show up above the container. My code is something like this:
// add the content container
UIView *contentContainer = [[UIView alloc] init];
[scrollView addSubview:contentContainer];
// add content, etc
// this works in 3.2+
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[scrollView addSubview:imageView];
// tried adding this for 3.1, but still didn't work
[scrollView bringSubviewToFront:imageView];
[imageView setFrame:CGRectMake(point.x, point.y, image.size.width, image.size.height)];
Is there something else that I'm missing? Thanks!

Are you also actually setting the contentSize property of the UIScrollView ?

Found the issue: when I specified the image name, I was not specifying the image extension:
UIImage *image = [UIImage imageNamed:#"myImage"];
If I change this to the following, it works:
UIImage *image = [UIImage imageNamed:#"myImage.png"];
Does iOS know to still look for the "#2x" version if available when the extension is present by chance?

Related

How to repeat image horizantly in dynamic creation in ios

Could any one help me i want to add same image multiple times horizontally with same height and width. Important thing is i am creating image view dynamically i want to use same image view for all images! This is image i want to make horizontally like this but only one row needed like this.
You could achieve this by using stretchableImageWithLeftCapWidth:
UIImage *backgroundImage = [[UIImage imageNamed:#"SheetBackground.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];
As per your request:
UIImage *backgroundImage = [[UIImage imageNamed:#"q4Ses.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];
[_scro setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
And using your image:
The output is:
You can set this image on top of either UIScrollview, UIView and buttons. You do not need a for loop for that.
UPDATE:
The above code is for filling the entire background. If you wish to add only for one row then you have to create one UIView and set its colorWithPatternImage like below:
UIImage *backgroundImage = [[UIImage imageNamed:#"q4Ses.png"]
stretchableImageWithLeftCapWidth:1 topCapHeight:0];
UIView *v=[[UIView alloc]
initWithFrame:CGRectMake(0, 0, _scro.frame.size.width, 45)];
[v setBackgroundColor:[UIColor
colorWithPatternImage:backgroundImage]];
[_scro addSubview:v];
And the output:
Make a view of the height of image. But this view can have any width.
Then set your tile image in this view with following code.
UIImage *tiledImage = [UIImage imageNamed:#"myTiledImage.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:tiledImage];
This will get you the image tiled multiple times horizontally.
If the view spreads the image everywhere on screen then you'll have to add the following code to your view
self.view.clipToBounds = YES;
UIScrollView *myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
CGFloat scrollWidth = 0.f;
for (int i=0;i<10;i++)//i=10,put as many image number u want to display
{
imageView = [[UIImageView alloc] initWithFrame:
CGRectMake(scrollWidth, 0, 80, 60.f)];
imageView.image=[UIImage imageNamed:#"urimagename"];
imageView.tag=i;
[myScrollView addSubview:imageView];
scrollWidth += 100;
}
myScrollView.contentSize = CGSizeMake(scrollWidth, 100);
EDIT:
You can achieve this in one more way.
CodenameLambda1's answer is better than the above one.But still some changes needs to be done in the #CodenameLambda1's answer..as the SOP's requirement is to display it in scrollview.So instead of self.view use scrollview.
UIScrollView *vie=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
UIImage *tiledImage = [UIImage imageNamed:#"login"];
vie.backgroundColor = [UIColor colorWithPatternImage:tiledImage];
vie.contentSize=CGSizeMake(1400,60);
vie.clipsToBounds = YES;
[self.view addSubview:vie];

I want to get imageView Position vertically upside down

In the Below image there are two imageViews one is body imageView and another one is black tattoo imageview ,
Now i am getting the tatoo imageView position with the below code
appDelegate.xFloat= self.imgView.frame.origin.x;
appDelegate.yFloat= self.imgView.frame.origin.y;
appDelegate.widthFloat= self.imgView.frame.size.width;
appDelegate.heightFloat= self.imgView.frame.size.height;
Now i need to put the tattoo image in another view controller as we are seeing in the image(Here Car is in reverse position), But with the help of (appDelegate.xFloat, appDelegate.yFloat, appDelegate.widthFloat, appDelegate.heightFloat) these I am setting the tattooimageview frame.
But i am getting the image as shown below in another view
I need to place the car image in reverse as we seen in first image.
Please Guide Me
My requirement is not only rotation.. The image may be in any position like below
It is strange that one image is not rotating and the other one is rotating. I am assuming that one of the images is a background image or what ever, but you can use transform properties to change the rotation. Some thing similar to the code below should show you the same image in two orientations.
UIImage *image = [UIImage imageNamed:#"image.png"];
UIImageView *iv1 =[[UIImageView alloc] initWithImage:image];
[self.view addSubview:iv1];
UIImageView *iv2 = [[UIImageView alloc] initWithImage:image];
[iv2 setFrame:CGRectMake(100,100,image.size.width,image.size.height)];
[iv2 setTransform:CGAffineTransformMakeRotation(-M_PI)];
[self.view addSubview:iv2];
you must contructor appDelegate before use it.
by:
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
Babul, Looks like you are trying to create an image. For that you need to use some thing called ImageContext. I have given some code, where you draw an image in a context and then get the image out.
UIGraphicsBeginImageContext(CGSizeMake(300,300));
UIImage *image = [UIImage imageNamed:#"breakpoint place.png"];
[image drawAtPoint:CGPointMake(0,0)];
UIImage *image2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *iv = [[UIImageView alloc] initWithImage:image2];
[iv setFrame:CGRectMake(100,100,image2.size.width,image2.size.height)];
[self.view addSubview:iv];

How can I add an image with coordinates in the UIView?

Is it possible to add an image in the UIView with specific coordinates?
If so, anyone who is keen on explaining how to?
You need to create an UIImageView and set it's frame to the desired coordinate.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:<#imageName#>]];
imageView.frame = CGRectMake(<#x#>, <#y#>, <#width#>, <#height#>);
[yourViewController.view addSubView:imageView];
Let me know if this works for you.
Something like this?
UIImageView *myImage = [[UIImageView alloc] initWithImage:someImage];
myImage.frame = CGRectMake(40, 40, myImage.frame.size.width, myImage.frame.size.height);
[myView addSubview:myImage];
That'll add an image, contained in an image view, at specific coordinates.
Yes, you have either to draw the image in -(void)drawRect:(CGRect)aRect;, by subclassing UIView, or to add an UIImageView as a subview of the main view, displaying the image.
Have a look on these :
UIImageView Class Reference.
UIView

uiscrollview not scrolling uiimageview

I'm trying to insert one more image in my UIScrollView. The problem is: all my old content is still scrollable, but this image stay static in the top of the page. Does anybody know a solution?
Code:
- (void)viewDidLoad {
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
myImage = [[UIImageView alloc] initWithFrame:myImageRect];
UIImage * img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"www.somelink.com"]]];
myImage.image = img;
myImage.opaque = YES; // explicitly opaque for performance
[scrollView addSubview:myImage];
[myImage release];
}
Regards.
I'm guessing that your "old content" is encapsulated in a view and it's that view that is your UIScrollView's subview for content. If that's the case, you should add your new image to that "contentView", adjust its frame and update the scrollview's contentSize based on the new width and height of the content view.
If my guess is wrong, could you please post the code showing how the UIScrollView is created and how the "old content" is added to it?
You might also find this sample code from Apple useful with regard to the layout of subviews of a UIScrollView. (see the - (void)layoutScrollImages method).

how can I use UIImageView on full screen in UIViewController?

I am developing a software and in it I am making a new file, which is subclass of UIViewController, when I do use UIImageView, then there is little border remaining in it, what should I do so that my image should cover all area around it,
my coding of UIImageView in ViewDidLoad is
UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: #"frontnew.png"]];
view.frame = CGRectMake(0, 0, 320, 415);
[self.view addSubview:view];
now what should I do ????
If I increase height and width then it will increase from two sides, not all ???
you should set imageview property as scalltoFit
May be it can help you