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

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.

Related

If I have 4 coordinates making a rectangle, how can I color in that area?

I have 4 coordinates assigned to variables, so I would just like to colour in the rectangle that is created from these variables. I tried the fill function, but I cant gather much information from the example.
When I try to use:
fill(bottom left point, top right point,'g')
the figure it makes only shows a line between those points, and doesn't colour in the entire area.
I'm using MATLAB R2019b, if that helps.
Also, if its possible to fill the rectangle with a pattern instead, please let me know aswell.
Thanks in advance

how to change the position of the output result in GUI

Does any one here have an idea about how to change the position of output in the GUI matlab to be to the right side of the box and not in the center ?
i think I have to change some properties of the result text box
Check this post out: Positioning of figures
The figure Position property controls the size and location of the figure window on the screen. Monitor screen size is a property of the root Handle Graphics object. At startup, the MATLAB software determines the size of your computer screen and defines a default value for Position. This default creates figures about one-quarter of the screen's minimum extent and places them centered left to right, in the top half of the screen.
The Position Vector
MATLAB defines the figure Position property as a vector. So you may use a figure and text into it, e.g.
figure(gcf)
text(offsetX1, offsetX1, ['result 1: ' num2str(result1)])
text(offsetX2, offsetX2, ['result 2: ' num2str(result2)])
Displaying analytical results in a MATLAB GUI
This post talks about adding a static textbox with your results and positioning it.
Move GUI figure to specified location on screen:
Syntax:
movegui(h,'position')
movegui(position)
movegui(h)
movegui
The answer is pretty much trying to cover up the vauge nature of the question

how to get x and y coordinates of user tap/touch relative to window - android titanium mobile?

Can any one tell how to get x and y coordinates of user tap/touch relative to window - android titanium mobile??
I need to add a popup view close to tableviewrow when the user select a row. How to determine the x,y (top/left) positions?
This might help you as the window or object touch events can help you find the exact points the user have touched on screen.
thanks
you can use
row.addEventListener('click',function(e){
alert('left:'+ e.x + ' top:'+ e.y);
});
where row is an object of Titanium.UI.TableViewRow. For other objects (like window/view), you can use same eventlistener.
But remember one thing: it gives the co-ordinates with respect to the corresponding row. i.e. you may get same co-ordinates for all the rows.
Therefor, if you want to popup something on that co-ordinate, you should addEventListener to the main window.
On click event of any view or object you get x and y coordinate see this link for more reference:
Titanium.UI.Window

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.

MATLAB: impoint getPosition strange behaviour

I have a question about the values returned by getPosition. Below is my code. It lets the user set 10 points on a given image:
figure ,imshow(im);
colorArray=['y','m','c','r','g','b','w','k','y','m','c'];
pointArray = cell(1,10);
% Construct boundary constraint function
fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));
for i = 1:10
p = impoint(gca);
% Enforce boundary constraint function using setPositionConstraintFcn
setPositionConstraintFcn(p,fcn);
setColor(p,colorArray(1,i));
pointArray{i}=p;
getPosition(p)
end
When I start to set points on the image I get results like [675.000 538.000], which means that the x part of the coordinate is 675 and the y part is 538, right? This is what the MATLAB documentation says, but since the image is 576*120 (as displayed in the window) this is not logical.
It seemed to me like, somehow, getPosition returns the y coordinate first. I need some clarification on this.
Thanks for help
I just tried running your code in MATLAB 7.8.0 (R2009a) and had no problems with image sizes of either 576-by-120 or 120-by-576 (I was unsure which orientation you were using). If I left click inside the image, it places a new movable point. It did not allow me to place any points outside the image.
One small bug I found was that if you left-click in the image, then drag the mouse pointer outside the image while still holding the left button down, it will place the movable point outside the image and won't display it, displaying a set of coordinates that are not clipped to the axes rectangle.
I'm not sure of what could be your problem. Perhaps it's a bug with whatever MATLAB version you are using. I would suggest either restarting MATLAB, or clearing all variables from the workspace (except for the image data im).
Might be worth checking to see which renderer you are using (Painter or OpenGL), a colleague showed me some wierd behaviour with point picking when using the OpenGL renderer which went away when using the Painter renderer.
Your code uses the Image Processing Toolbox, which I don't have, so this is speculation. The coordinate system is probably set to the figure window (or maybe even the screen), not the image.
To test this, try clicking points outside the image to see if you can find the origin.