UIImageView* XXX = [[UIImageView alloc] initWithImage:XXX] - iphone

WHat does this line of code :
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
if it help Then I have this :
int startX2 = round(random() % 480);
// set the flake start position
flakeView.frame = CGRectMake(startX2, 330.0, 30, 20);
flakeView.alpha = 1;
// put the flake in our main view
[self.view addSubview:flakeView];

The line:
UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
creates a container "UIImageView" object that contains an image "UIImage" stored in an ivar flakeImage
The rest of the code positions flakeView on the main view with assigned x,y,width and hight properties.

Related

Can't get UIBezierPath onto of MKMapView

I've got a MKMap, on top of this I have a little legend. The labels & images inside the legend successfully show on top of the map, but the rectangle/bezier itself doesn't show.
I've tried adding it as a subview and that fails. Is there a way around this?
I need touch to still be enabled for the map.
Thanks.
- (void) drawRect:(CGRect)rect
{
//TODO
//Hover view for touching icons
//Get rect on top of map as well
//Border on frame
//IsIpad slight larger frame/text/image
int conX = [GeneralHelper GetCenteredXPosForObj:220 :self];
int conY = 60;
//Create box
CGRect container = CGRectMake(conX, conY, 220, 50);
UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:container cornerRadius:5.0];
[[UIColor blueColor] setFill];
[path fillWithBlendMode:kCGBlendModeNormal alpha:0.7];
//How to add to subview..?
//NZPost image 38x37
UIImageView *nzPostImageView = [[UIImageView alloc] initWithFrame:CGRectMake(conX + 20, conY+15, 25, 24)];
[nzPostImageView setImage:[UIImage imageNamed:#"icon-map-post.png"]];
[self addSubview:nzPostImageView];
//NZPost label
LegendLabel *postLabel = [[LegendLabel alloc] initWithFrame:CGRectMake(conX + 50, 78, conY, 15) ];
postLabel.text = #"NZ post";
[self addSubview: postLabel];
//Incharge image 38x38
UIImageView *inChargeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(conX + 120, conY+15, 25, 24)];
[inChargeImageView setImage:[UIImage imageNamed:#"icon-map-incharge.png"]];
[self addSubview:inChargeImageView];
//Incharge label
LegendLabel *inChargeLabel = [[LegendLabel alloc] initWithFrame:CGRectMake(conX + 150, conY+18, 60, 15) ];
inChargeLabel.text = #"In charge";
[self addSubview: inChargeLabel];
}

iPhone - Set UIImage position

I want to have an image that moves each time I hit a button. It should move a set value of pixels each time.
I was hoping that image1 now would have a position property, but as far as I can see it doesnt't.
UIImageView *image1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"indicator"]];
[self.view addSubview:image1];
...
Thank you
EDIT: UIImageView *image1=[[UIImageView alloc]...
As the other two answers state, you can set the initial position of a UIImageView using a frame (or CGRect). Note that the parameters for the CGRectMake are; x position, y position, x dimension, y dimension.
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
[imgView setImage:[UIImage imageNamed:"image.png"]];
To move the image each time you press a button, you'll need to update the frame each time the button is pressed. However, the x and y coordinates of a frame are read only, so you'll need to create a new frame like so:
CGRect oldFrame = imgView.frame;
CGRect newFrame = CGRectMake(oldFrame.origin.x + 10, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
imgView.frame = newFrame;
Note that this code moves the image 10 points to the right, (along the x axis).
you need an imageview to display an UIImage.
UIImage *image1=[UIImage imageNamed:#"indicator.png"];
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100)];
iv.image = image1;
[self.view addSubView:iv];
[image1 release];
[iv release];
You can set the frame of the UIImageView:
UIImageView* imgv= [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
imgv.image = [UIImage imageNamed:#"image.png"];
Here you will have to set the position of frame by trial and error.

iOS 5, Can't set NC Widget UIView height

I am creating a NC Widget and can't seem to adjust the height of the widget.
Here is my code:
-(UIView *)view {
if (_view == nil)
{
CGRect frame = CGRectMake(2,0,316,191); // Added
_view = [[[UIView alloc] initWithFrame:(frame)] autorelease]; //(2., 0., 316., 71.)]; <--ORIGINAL VALUE
// Setting frame Height dont work... :/
UIImage *bg = [[UIImage imageWithContentsOfFile:#"/System/Library/WeeAppPlugins/SMSWidget.bundle/Background.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:71];
UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];
bgView.frame = CGRectMake(0, 0, 316, 191);
[_view addSubview:bgView];
[bgView release];
}
This is an example of how you can do that :
float myWidgetHeigth = 500 ; // The desired height
_view = [[UIView alloc] initWithFrame:CGRectMake(2, 0, 316, myWidgetHeigth)];
UIImage *bg = [[UIImage imageWithContentsOfFile:#"/System/Library/WeeAppPlugins/WorldClockNC.bundle/WeeAppBackground.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
UIImageView bgview = [[UIImageView alloc] initWithImage:bg];
bgview.frame = CGRectMake(0, 0, 316, myWidgetHeigth);
[_view addSubview:bgview];
If you are developing a plugin for the notification Center, refer to the BBWeeAppController-Protocol.h you will need also to implement this method : "- (float)viewHeight".
Also, I have seen from your code you are using theses methods "stretchableImageWithLeftCapWidth:5 topCapHeight:71", that are deprecated in IOS 5.0 --> https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight: So, use the method "resizableImageWithCapInsets" ;-).
I'm not a pro on it, I'm learning ObjC, so if you have somes questions, let me know.

apply zoom event with array of images of image view in UIScrllView

- (void)viewDidLoad
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
int numberOfImages = 32;
CGFloat currentX = 0.0f;
for (int i=1; i <= numberOfImages; i++) {
// create image
NSString *imageName = [NSString stringWithFormat:#"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
// put image on correct position
CGRect rect = imageView.frame;
rect.origin.x = currentX;
imageView.frame = rect;
// update currentX
currentX +=454; //mageView.frame.size.width;
[scrollView addSubview:imageView];
[imageView release];
}
[scrollView addGestureRecognizer:tapGesture];
scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];
}
}
in above code when i apply zoom or tap event with a single image then it work for that. But when same event apply for array of image then not working. why is it happened?
Its quiet complex to implement zoom in this kind of image flow. Anyway i wil suggest you one idea,
Add the gesture to each imageView. In the method, add a new scrollview, with the respective imageView.. then implement zoom.
EDIT:
In the tapgesture method,
1.Find out the which imageView is visible at that time.
2.Then create a new scrollview,with that single imageview.
3.Implement zoom functionality in that new scrollview.
4.During zoom out,If the new scrollview size is equal to the actual value,remove the new scrollview fro the super view so that the array of images is visible.
Simplest way is create a big wrapper view first, and insert it into ScrollView.
And then add all your imageViews to the wrapper view.

Add image into UIActionSheet

How to Add image into UIActionSheet?
Try this:
(void)willPresentActionSheet:(UIActionSheet *)actionSheet{
UIImageView* df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourpic.png"]];
df.center
[actionSheet addSubview:df];
//scale image aspect to fit image view
df.contentMode = UIViewContentModeScaleAspectFit;
//change width of frame
CGRect frame = df.frame;
frame.size.width = 50;
df.frame = frame;
}
It will resize it as shown.