iPhone - How to partially hide the subview? - iphone

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.

Related

UIButton title label transform cuts off label

I am creating a UIButton with interface builder of size 30px width and 164px height.
I want to rotate title of UIButton to 90 degrees.
I am using following code for rotation
// leftNavBtn1 is a UIButton
self.leftNavBtn1.titleLabel.transform = CGAffineTransformMakeRotation(-M_PI / 2);
The problem is after rotation the label cuts off. I have tried to programatically set title but its not work.
I want to achieve like this
What i am getting
The titleLabel property is primarily used to configure the text of the button, not its bounds.
I don't think you can achieve what you want to achieve.
If I understand you correctly, you make a button with a small width and big height in interface builder, then set the transformation on the label of the button to 90º, and then expect the button to behave as if the width became the height and vice versa.
I suppose you could still set the button in interface builder, but make it horizontal, as if it's rotated -90º, and then set the transformation on the UIButton in viewDidLoad
Maybe it's stupid, but have you tried creating a label over your button and then apply the same rotation?
It's not elegant but can work

Covering space from one UITableView's cell with another one

The design of the UITableView is something like this:
I want to make my cells with a tiny triangle, like in a comic book. The thing is, how can i add the triangle to the size of my custom cell? The common rectangle size wouldn't work if i want the user to be able to tap that little rectangle.
And how can i make the opposite? I want the triangle to cover the space of another cell, so tapping the little triangle of the first cell, covering part of the second cell's rectangle space, would activate de first one. This is, substracting a little triangle from the cell's space.
Not sure it would work, but building on user697562's comment, you could try the following:
Add a small UIView to the table cell to represent the small triangle
Rotate it using its transform property, making sure that, along with its frame, it will have the proper placement.
Add a UITapGestureRecognizer to the UIView
Add an instance variable to the view to save the indexPath of the cell it's in (or even the above cell, since it will be associated with the above cell). This way when the gesture recognizer is triggered, you know what row you're in.
Write the action method associated with the gesture recognizer to do the same thing as tableView:didSelectRowAtIndexPath: would do for the above cell.
Set the separatorStyle property of the UITableView to UISeparatorStyleNone, so that it won't draw the lines between cells. If this doesn't work just set the separatorColor property to your table cell's background color.
Draw a border along the top & bottom of the cell, accounting for the triangle.
Good luck with it! Let me know whether it works if you try it.

label and scroll view

HI FRIENDS..
I use a scroll view and a label now i want that when i scroll that , label also scroll with that and set to next location , i set paging enable = YES , so i want that there are 5 images and when i did scrolling the label i set is also move and show in other position.
thanks
To scroll a UILabel (or anything for that matter) WITH a UIScrollView, simply add the label to the UIScrollView.
You can easily do this in Interface Builder by the obvious methods.
You can also do this programmatically by utilizing the addSubview: method.
You can do one thing you change frame of label when you scroll in delegate method of scrollview or you can also make 5 same label in all 5 pages.
Good Luck
Well if you have added a scrollview on top of a uiview you can add that label on the view and then bring it to front. then you dont have to worry about changing frame of the uilabel as it will be always on top of the scrollview and at the same position and also you can change the text of that label when the user scrolls in pagecontrol value changed method.

Detect if a UILabel hide another UILabel on same UIView

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
}

Iphone Custom Scrollview indicator

I am currently working on an application for a client, and they have made an odd request. The request involves putting a custom image as the indicator for the scrollview. I am not even sure if this is possible but if it is can you please let me know how one would go about doing that.
Thanks
UIScrollView streches a small, semi-transparent circle image to generate its scrollbars. You can find this image as the first subview of a UIScrollView:
UIImageView *circle = [scrollView.subviews objectAtIndex:0];
However, as I said this image is stretched, and as far as I can tell, only the alpha values are considered when drawing the scroll bars.
So for example if you're only interested in changing the top/bottom ends of the scroll bar, you can try to change this image. However, I doubt you'll be able to do anything interesting.
A possible solution that comes to mind, and this is only a theory, is to add a custom, transparent UIView on top of a UIScrollView. Then you can hide the default scroll bar (by using showsHorizontalScrollIndicator and showsVerticalScrollIndicator), pass the necessary touch events to the UIScrollView to scroll the content, and draw the scrollbars in your custom view.