Find out which segment the image resides in objective c - iphone

I have created a rotating wheel of 5 images. What I would like to find out is which image ends up in the top right corner.
Is there any way I can realize which one is in the top right corner through coding?
Thanks :)

If your images are going to end up in specific spots, meaning you know exactly what will be the position of an image when it is in the 'top right corner', you can check the origin (of directly the frame) of that image view.
BOOL bingo = CGRectEqualToRect(imageViewRect, topRightCornerRect);
or
BOOL bingo = CGPointEqualToPoint(imageViewOrigin, topRightCornerRectOrigin);

Related

Center image in group JavaFX

I'm trying to make some figures in JavaFX. I can create these figures with the Polygon class or in this case with the Circle class. But I want to add an image on top of it. So I'm using a group for this with 2 elements, the figure and the image in an ImageView. But if I use this group, the image isn't in the middle. I would like to center the image. I also would like to be able to drag and drop it with a mouse, so then it needs to stay in the middle. I've tried it with a circle and a polygon but in both cases the image was in the bottom right corner.
Edit: I just figured out that you can move your image with setX and setY, but this isn't an easy way to center the image.
Here's what I have at the moment:
public class Figure extends Group {
public Figure() {
Circle circle = new Circle(100);
ImageView imageView = new ImageView();
circle.setFill(Color.BLUE);
circle.setStroke(Color.BLACK);
Image image = new Image("images/blue/bike.png");
imageView.setImage(image);
imageView.setFitWidth(100);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
super.getChildren().addAll(circle, imageView);
}
The easiest solution would be to use a StackPane instead of a Group. That might give problems with clickability if you let them overlap: one of two Circles is then obscured by the other figure's StackPane.
Though a bit inelegant, I would do it with setX and setY as you propose.

Trying to position a button programmatically, however not in right position according to X,Y

I'm trying to position a button.
Here is the code for the positioning..
[btnAbs setFrame:CGRectMake(57, 50, 106, 99)];
The coordinates I got are from here:
As you can see the xib stats the x & y to be at 57 and 192, which is where I want the button to be.
However when I run it in simulator, here is where its placed:
Obviously i could keep guessing and guessing the x and y coordinates, but this is very time consuming. So how come it's doing this?
Please join the links together when looking at the pics as i need more than 10 reps to post images, or a mod fix this please?
The problem is here:
The “origin” in Interface Builder doesn’t actually affect how the view gets positioned programmatically—it’s just a visual aid. If you click the dot in the top left of that box, the X and Y coordinates will change to the top-left of the view, which are the coordinates you want to pass to -setFrame:.
It looks to me as if you have the GUI designer aligning base upon the center center of your image view. When you do it in code, it is going to align based upon the top left of the image view.
Further, your code places it at a y of 50, where your GUI designer is showing a y coord. of 192.

iPhone : How does the co-ordinates will be set in following code?

In one of the demo code I found following type of coding.
btnLeftCard.center = CGPointMake(385.0f, 300.0f);
btnRightCard.center = CGPointMake(385.0f, 770.0f);
Can anybody give me some idea for this coding ?
The btnLeftCard and btnRightCard will be added to a parent view. The top left of that view acts as origin (0,0). The co-ordinates(x,y) will be added with respect to this point. As you go right the value of x changes and as you move below value of y changes with respect to the origin.
CGPointMake. I think it's all you need.
btnLeftCard.center = CGPointMake(x, y);
point (x,y) will be the center of the btnLeftCard. i.e. btnLeftCard has a rectangular area.
Then half of its width and height will be top and left of this point and other half will be at right and bottom of this point.

Increase UIView's frame size at the left edge

I have an UIView that can grow dynamically in width. The view also have subviews located inside it's bounds.
Default behavior seems to be that when the view's frame grows along the x axis, increasing frame.size.width, it always grows at the right edge, keeping the subviews fixed as if there were a fix left margin. However, when I want to expand the view on the left edge this doesn't work because of this behavior. In this case I want it to behave in a mirrored way, as if there were a fix right margin. I could of course "manually" move all subviews so it looks like that is the case, but that seems really awkward since there could be plenty of them.
So I guess the question really is if there is a way to shift a views bounds relative to it's subviews? Is maybe autoresizingMask the way to do this?
Thanks.
Maybe you should take a look at the AutoresizingMask property of a UIView subclass :-)
For example, if you have a UILabel called labelVideoTitle, you could set a mask like this :
[ labelVideoTitle setAutoresizingMask:UIViewAutoresizingFlexibleWidth ];
You can by the way add 2 mask at once like :
[ labelVideoTitle setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];
Good Luck !
Edit : To increase the parent view frame size at the left edge, you could change too its X position to the left to give the impression wanted ^^ For example if you add 10 pt to the width, try modifying the X origin -10 pt :-)
In interface builder, you can graphically indicate in the CMD-3 (little ruler icon) Size Inspector what each element in your view should do when the parent view is resized: you can indicate which borders (top, left, right, bottom), the given element should "stick to" when the parent view is resized. You can also indicate whether the given element should itself resize (in either width or height) or stay the same size. Underneath the hood, this sets the autoresize mask for the UIView element you're editing, but especially for making an element stick to a particular border, Interface Builder is the way to go.
IB Size Inspector also has a neat little animation that shows you the effect on a hypothetical element (little red square) during a resize, given your settings to the left.

StretchableImageWithLeftCapWidth stretching wrong portions

I am trying to use a UIImage with stretchableImageWithLeftCapWidth to set the image in my UIImageView but am encountering a strange scaling bug. Basically picture my image as an oval that is 31 pixels wide. The left and right 15 pixels are the caps and the middle single pixel is the scaled portion.
This works fine if I set the left cap to 15. However, if I set it to, say, 4. I would expect to get a 'center' portion that is a bit curved as it spans the center while the ends are a little pinched.
What I get is the left cap seemingly correct, followed by a long middle portion that is as if I scaled the single pixel at pixel 5, then a portion at the right of the image where it expands and closes over a width about twice the width of the original image. The resulting image is like a thermometer bulb.
Has anyone seen odd behavior like this and might know what's going on?
Your observation is correct, Joey. StretchableImageWithLeftCapWidth does NOT expand the whole center of the image as you would expect. It only expands the pixel column just right of the left cap and the pixel row just below the top cap!
Use UIView's contentStretch property instead, and your problem will be solved. Another advantage to this is that contentStretch can also shrink a graphic properly, whereas stretchableImageWithLeftCapWidth only works when making the graphic larger.
Not sure if I got you right, but LeftCapWidth etc is made for rounded corners, with everything in the rectangle within the rounding radius is stretched to fit the space between the 'caps' on the destination button or such.
So if your oval is taller or wider than 4 x 2 = 8, whatever is in the middle rectangle will be stretched. And yours is, so it would at least look at bit ugly! But if it's not even symmetrical, something has affected the stretch. Maybe something to do with origin or frame, or when it's set, or maybe it's set twice, or you have two different stretched images on top of each other giving the thermometer look.
I once created two identical buttons in the same place, using the same retained object - of course throwing away the previous button. Then I wondered why the heck the button didn't disappear when I set alpha to 0... But it did, it's just that there was a 'dead' identical button beneath it :)