I have a UIView Just like images aligned in gridlike view.
Created using the code.
for (int i=_farmView.bounds.origin.x; i<_farmView.bounds.size.width; i+=originalBagWidth*2) {
for (int j=_farmView.bounds.origin.y; j<_farmView.bounds.size.height; j+=originalBagHeight*2) {
//adding bag
n+=1;
CGRect frame = CGRectMake(i, j, originalBagWidth, originalBagHeight);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *image = [UIImage imageNamed:#"bag"];
image = [self imageResize:image andResizeTo:v.bounds.size];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[v addSubview:imageView];
[_farmView addSubview: v];
[v setBackgroundColor: [UIColor darkGrayColor]];
}
}
And I have added proper Code for zooming the UIView using Pinch Recognizers. Now when user zooms the UIView The Image Becomes unclear.
I want to grow the pixel size when zooming the UIView. How can i
achive this functionality
Note: The number of UIImages inside UIView and size of UIView is decided at runtime and cannot be predicted.
Related
I create a UIImageView and add to VC UIView , then I create a image with animatedImageWithImages:duration:
When I execute the code, it works normally. It displays image animation. But when I push to next VC and in the process of swipe back , I find the UIImageView display nothing.
At the moment finger left screen , everything back to normal.
Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imgView = [[UIImageView alloc] init];
imgView.backgroundColor = [UIColor orangeColor];
imgView.frame = CGRectMake(20, 200, 80, 80);
[self.view addSubview:imgView];
NSArray *imgs = #[[UIImage imageNamed:#"img1"],[UIImage imageNamed:#"img2"]];
imgView.image = [UIImage animatedImageWithImages:imgs duration:0.5];
}
BugGif
I notice the imageView has CAKeyframeAnimation. I guess the conflict that runmode and CAKeyframeAnimation.
SDWebImage has the same problem. Because it also use the method that create UIImage. I think the point is the method of animatedImageWithImages:duration: and CAKeyframeAnimation.
Anyone knows the solution? Thanks a lot.
The event that the finger left the screen will make imageView display normally. Why and How to resolve?
GitHubBugDemo
You can use UIImageView another methods to set images and animation duration as below
UIImageView *imgView = [[UIImageView alloc] init];
imgView.backgroundColor = [UIColor orangeColor];
imgView.frame = CGRectMake(20, 200, 80, 80);
NSArray *imgs = #[[UIImage imageNamed:#"img1"],[UIImage imageNamed:#"img2"]];
[imgView setAnimationImages:imgs];
[imgView setAnimationDuration:1];
[imgView setAnimationRepeatCount:HUGE_VAL];
[imgView startAnimating];
[self.view addSubview:imgView];
I created an UIView.
I need to set a small image on a particular position.
I can do it setting the image in a small separate view.
But, I plan to do it dynamically on a Large UIView which is full screen.
Thanks.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,200)];
view.backgroundColor=[UIColor clearColor];
[self.view addSubview:view];
// add image in view
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(50,50,20,20)];
imageView.image=[UIImage imageNamed:#"image.png"];
[view addSubview:imageView];
That is what views are for: manipulating UI widgets.
By far, your best approach is to position a UIImageView.
You can also override the view drawing methods:
override func drawRect(rect: CGRect) {
// Curstom
}
Try this code.
UIImage *image = [UIImage imageNamed:#"imagename.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//specify the frame of the imageView in the superview , here it will fill the superview
imageView.frame = catView.bounds;
// set custom frame as per your requirement
//or
// imageView.frame = CGRectMake(10,10,30,30);
//or
//according to superviews frame
//imageView.frame=CGRectMake(10,10,yourUIViewObject.bounds.size.width/2,yourUIViewObject.bounds.size.height/2);
// add the imageview to the superview
[yourUIViewObject addSubview:imageView];
I'm developing a iOs app for iPad and I'm implementing a UIImageView inside a UIView. The problem is that if the position of the image view has a position out of the UIView that it is inside, you can see it. The code:
UIView *vistafunda = [[UIView alloc] initWithFrame:CGRectMake(512/2, 48, 525, 651)];
[self.view addSubview:vistafunda];
vistafunda.backgroundColor = [UIColor darkGrayColor];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"hola.png"]];
img.center = CGPointMake(12, 200);
[vistafunda addSubview:img];
I would like that the image view was always under the view, so if the image is outside the view you could not see it.
Thanks!
Just make the containing view clip it's children
vistafunda.clipsToBounds = YES;
I have a subview in my app that contains a UIImageView. The user can touch this subview and move it around. I have some UILabels that I want to "stick" or group with the subview so that they move along with it. I wonder how to do that?
Here is where I add the Labels to the subview:
- (void)viewDidLoad
{
[super viewDidLoad];
//Decrease the site of root CALayer of the view and give it round corners
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 10.0;
self.view.layer.masksToBounds = YES;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 40, 40);
//check if the background is from the photo library and create a sublayer for the semi transparent white badge and a textsublayer for the countdown labels. Also hide the regular view labels
NSString *path = [_occasion imagePath];
if (path != nil && [path hasPrefix:#"ass"])
{
//Make a subview with a UIImageView inside for the badge
CGRect badgeRect = CGRectMake(32, 13, 236, 222);
UIView *badge = [[UIView alloc] initWithFrame:badgeRect];
imageView = [[UIImageView alloc]initWithFrame:[badge frame]];
[imageView setImage:[UIImage imageNamed:#"badge.png"]];
[badge addSubview:imageView];
[self.view addSubview:badge];
/*[self.view bringSubviewToFront:countDownLabel];
[self.view bringSubviewToFront:daysLabel];
[self.view bringSubviewToFront:hoursLabel];
[self.view bringSubviewToFront:minutesLabel];
[self.view bringSubviewToFront:secondsLabel];
[self.view bringSubviewToFront:daysName];
[self.view bringSubviewToFront:hoursName];
[self.view bringSubviewToFront:minutesName];
[self.view bringSubviewToFront:secondsName];*/
[badge addSubview:countDownLabel];
[badge addSubview:daysLabel];
[badge addSubview:hoursLabel];
[badge addSubview:minutesLabel];
[badge addSubview:secondsLabel];
[badge addSubview:daysName];
[badge addSubview:hoursName];
[badge addSubview:minutesName];
[badge addSubview:secondsName];
//more code for recognizing the touches on the subview
Just put them on the UIImageView and they'll move along with it.
You can get the position of your subview and change the position of you labels according to that.
I have a label (many labels in fact) now I want an image in the background of my label (same image) so that text writtenin my label is shown to user. How to do it programmatically?
The simplest way would just be to simply layer a UIImageView behind the UILabel. If you wanted to make it more robust you could make a UILabel subclass that exposes a method or property to set the image background and it would add the image to itself.
CGPoint labelPos = CGPointMake(123, 234);
UIImage *theImage = [UIImage imageNamed:#"button_bg.png"];
UIImageView *theImageView = [[UIImageView alloc] initWithImage:theImage];
theImageView.frame = CGRectMake(labelPos.x, labelPos.y, theImage.size.width, theImage.size.height);
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelPos.x, labelPos.y, 100, 50)];
theLabel.backgroundColor = [UIColor clearColor];
// ...label config...
[self.view addSubview:theImageView];
[self.view addSubview:theLabel];
[theImageView release];
[theLabel release];