I'm developing an iPhone application.
I have a UIView used to augmented reality. I add some UILabel to that UIView dynamically and I want to know if there is a way to know when a UILabel hide another UILabel added on same UIView.
In other words: I'm adding UILabels at the middle of the screen (y position is always the same, x can vary). When I'm going to add another UILabel, I want to know if there is another UILabel at the same position.
Note: A UILabel will have a (x,y) origin position and a height and a width.
Maybe there is a method to know where are "located" subview from a UIView.
Thanks.
If you do not apply any transforms to your views you can use CGRectIntersectsRect functions to views' frames:
if (CGRectIntersectsRect(label1.frame, label2.frame){
// Intersect
}
Related
I have a UILabel centered within a UIView that expands/contracts depending on the device screen size. I've applied constraints so that the UILabel remains centered no matter the UIView size, which works fine.
Now I'm finding myself resizing the UIView manually like so (where mainView is the View Controller):
self.myView.frame = CGRectMake(0,0,self.mainView.frame.width, self.mainView.frame.height)
So this stretches the UIView to fill the whole screen/View Controller (it's also animated). I assumed the UILabel would continue to centre itself automatically, but it seems to pin itself as though it were constrained to the top of the UIView, leaving a lot of empty myView space below it.
How can I tell the UILabel to remain in the centre of the height-changing UIView that it's in?
We need to see your constraints to help, but:
You need to use centering constraints.
Set the bounds, not the frame of myView.
You might need to call setNeedsLayout on the view of the ViewController you are in
Also, set the background color of the UILabel -- it could be centered, but the text is not centered inside of it. For that, set the alignment properties.
I have an array of images and must be scrolled horizontally which i could manage, But in each image the description of the image but be scrolled upwards above the image something like i shown in the image. How it is possible?
Thanx
Jacu
Use a (horizontal) UIScrollView that contains UIView's. Each of the UIView's then contains an UIImageView, and another (vertical) UIScrollView that contains the UITextView's.
Make sure that:
the contentSize.height of the horizontal UIScrollView is smaller than or equal to its height
the contentSize.width of the vertical UIScrollView is smaller than or equal to its width
the UIImageView is added before the UIScrollView to the containing UIView
the background of the UITextView is (semi-)transparent
By the way, if the text is not editable, then you'll be better off using UILabel instead of UITextView
I got a UIView that contains an UIIMageView and several buttons that are allocated on certain position related to the image of the UIIMageView.
The frame of the UIView is (0,0,250,250)
the UIIMageView that is within the UIView is set to autorisizing (all) in IB.
All buttons are set to autoresize (none) and origin middle.
When i change the frame of the UIView i.e (0,0,500,500) the UIIMageView (and image) resize OK but the buttons lose their perspective position by a few pixels (about 2 to 3 in the vertical and horizontal axis).
Is this normal? can someone advise?
Try putting the buttons inside another UIView and then setting the autoresizing options on this new view. You should leave the buttons without autoresizing inside the new view.
there is no answer after all.
I must accept the fact that the resized view and the buttons within it will lose perspective position by 2/ 3 pixels off the x/y axis...
strange....
I am developing one sample application using gestures, where i can pinch, pan and rotate. I have one main image view width and height is 300 and origin x is 0 and y is 70. This imageview I am using from interface builder. After this i am adding one label programmatically on the middle of the imageView. After adding the label I can able to pan, pinch and rotate the label on the view. Now the actual requirement is when i drag the label outside the imageview I should be display the partial label, for example (My label text is ABCDXYZ). As soon as I drag the Z outside the Z should be invisible, other part ABCDXY should be visible. More clear is drag the one view inside other view. How can i achieve this.
What you have to do is create a UIView. On that add the UIImageView like
[View addSubView:ImageView];
then add the UIlabel on the UIImageView like
[ImageView addSubView:Label];
Now set the clipsToBounds = YES. I think now your issue of the partial label would be solved as the label would move within the UIView and as soon as it goes out it would be shown partially. Any doubt please tell . Thanx :)
Its really tricky to give handheld solution for this, instead it could be a suggestion. I assuming that your UILabel text is dynamic, there's some scenarios you can follow to achieve this.
1) When you touch your label inside UIImageView you shoud get the exact coordinates of it.
2) Get the position where user touch on UILabel.
3) Compare the touch coordinates with total coordinates of UILabel.
4) Assume which character did touched. (You should make test of it, also text size may also matters).
5) When user drag that particular character (say Z) you need to remove that from UILabel text.
That's all. You're done.
I have a UIViewController subclass which has the view property set to a UIScrollView subclass (say ProfileScrollView). Now, I have overridden drawRect: method, in which I draw a lot of text and place UIButtons as subview in between texts. Depending on the text data, I set contentSize of the scrollView in this drawRect: method. Now, when I scroll this view the buttons are scrolling but the text remains stagnant. Please help with this problem. Thanks
I think your problem comes from the fact that you use drawRect: for your text. I'm pretty sure the positioning given by the CGRect argument is absolute and not depending on the scrollView's content's current offset.
Did you add your subviews (buttons and text) directly in the UIScrollView? If you did, try to insert a simple UIView in UIScrollView, which will contain all subviews. Should be something like this:
-> UIScrollView
-> UIView
-> UIButtons
-> Text
-> ...
So drawInRect: will draw the text in containing UIView with an absolute position, and UIScrollView will make UIView (and consequently all its contents) scroll.