Xcode cant click button after moving button frame - objective-c

I created a button in the Interface Builder with a tag 10
In code
UIButton *btn = (UIButton*)[self.view viewWithTag:10];
btn.frame = CGRectMake(btn.frame.origin.x,btn.frame.origin.y+changeInPos, btn.frame.size.width, btn.frame.size.height);
changeInPos could be any number lets say its 100. So my button moves down 100 but it no longer works in its new position nor does it work if I click where it used to be.
Have I done something wrong after moving the button? If its useful to know I have turned off use autolayout.

One possible explanation is that the button moves out of the frame of its containing view. In this case, it will not receive touches.

Related

Change Button Width and Height Programmatically Xcocde

I have an app that you tap a button and at certain points you get time added. I want to add to the app that whenever the certain point is met, the button height and width get smaller. How would I go about doing that?
If your button is named, say, button, this will make it 5 pixels smaller in all directions:
[button setFrame:CGRectInset(button.frame, 5, 5);
You can have more freedom by using any CGRect value you wish; but setFrame is the way to go.

Adjusting UIbutton Image

My UIbutton was stretching my images I was assigning to it with
[self.BTN_pic_1 setImage:myPIC forState:UIControlStateNormal];
I used this code to the correct resizing mode like this
[self.BTN_pic_1 setContentMode:UIViewContentModeScaleAspectFit];
The aspect fit only works once I press the button. I want the Aspect Fit to start working as soon as I load the image.
How can I get the button to do that?
Use the imageEdgeInsets to control how the image is stretched.
or
Set the contentMode of the button's imageView instead of the button's.
[self.BTN_pic_1.imageView setContentMode:UIViewContentModeScaleAspectFit];
Disclaimer:
There are many posible answers to this, you'll probably need to be more specific before we can give you a definitive answer.
It is not the button's content mode you want to fix; it's the content mode of the button's imageView. That is what is holding the image you assign when you call setImage:forState:.

UIButton in UICollectionViewCell resets its label text to what is set using storyboards from the runtime text being set on every click

I am working on an app having a collection view with Collection view cells having 4 buttons to invoke different actions.Each links to a different IBAction. I have read multiple threads across the board and had decided to use storyboards rather than go at it programmatically since 'this could be the way forward'. So while setting up the buttons, I had set default label text to Button 1, Button 2 etc. In the code, while giving cell for index path, I am changing the button text to something programmatically. When the application is run the cells render fine with dequeueing, and the text being set programmatically is set correctly. However, when I click any of the buttons, the action is called, but the label text of the button resets to what was set using storyboards.
I have tried everything to retain the text label copy to what it should be. But to no avail. When I again dequeue the cell by scrolling across the collection view and the view gets redrawn, the button again gets the correct text.
Can anyone please shed some light on why the button text for a button placed in a collection cell will reset its text and will not allow it to be set unless the view is redrawn.. Also any ideas on how to fix this.
Thanks a ton
deej nailed it --
I had the same problem but was doing something stupid:
self.btnProperty.titleLabel.text = #"button title";
rather than:
[self.btnProperty setTitle:#"button title" forState:UIControlStateNormal];
Use the latter.

Resize UIView to hide the portion under the "cut line"

I am designing an editable UITableViewCell*. In the normal state, my cell should look like the portion of this image above the red line.
When users click [Edit...], the controls letting the user change the settings will show up, and the text of the [Edit...] button will become [Done]. Clicking [Done] will hide the portion below the red line, and change the text on the button back to [Edit...].
I am trying to achieve this effect by changing the height of the row in the delegate. When the cell is in edit mode, it's returning the full height; when the cell is not in edit mode, the height of the upper portion from the red line on is returned. Unfortunately, when I do that, the edit controls "slide up", obscuring the rest of the cell. I am fixing this by making these controls invisible in the edit mode, but I think there should be a better solution.
Are there settings that I could apply to the controls in order to let me cut off the bottom, clipping the content below the red line?
* I am using Interface Builder to design my cell, in case it matters.
In your xib - just turn on the top strut
This is working for me. To make it smoothly expand and contract you'll need to use the trick of an empty beginUpdates/endUpdates call
[tableView beginUpdates];
[tableView endUpdates];

uiscrollview and uibutton behaves transparent for touch events

I have a custom subclass of UIView and a full screen UIButton with a background image on it as you can see in the image,
on the right side, there is a UIView with a UIImageView on it and some other not important labels and buttons. The important part is, there are two scrollviews on that UIView and at the run time, i add UIButtons ( not small ones, 200 x 100 ) on those scrollviews with vertical scrolling enabled.
The situation is really very complex so i will write as items what happens in different conditions. In my application, there are 10 of these complete screens, on a custom subclass of UIView and i use UIPanGestureRecognizer to scroll from one to other.I have a good reason not to use a scrollview for this. All the windows ( the below image, not UIWindow ) populates their content in a loop, so the running code is exact same for all of them and all of them are being created from the same .xib file. And the last information, the bigger UIButton that covers all the window has an action for touchupinside and the smaller buttons in scrollviews have their own touchupinside selectors.
Some of my windows works perfectly, if i touch anywhere on the screen, the bigger buttons action is called, if i touch and drag, the scroll works and i navigate to the next / previous window, if i touch on smaller buttons in scrollviews, their actions fired and lastly i can perfectly scroll within those buttons.
Some of my windows, when i try to scroll the scrollviews, the bigger windows pangesturerecognizer catchs this event not the small scrollviews, and if i touch the small button in that scroll view, the bigger buttons event is fired ( it pass all through uibutton > uiscrollview > uiimageview > uiview to the uibutton at the button like they dont exist )
if i replace the right container view some other position on the big uibutton, it randomly works well or not, sometimes one of the scrollviews works well and the other not.
it has a consistent behaviour, if on a one position, it works, it allways works, and if it not, it never does.
Again, all the views and subclasses have their userinteraction enabled yes, the opposite is already imposible because the behaviour changes only acording to position of container view on the big uibutton and also changes acording to big uibuttons background image.
I've placed a touchesBegan method for just test purposes, when the touches does not work as expected, the event fired with touch.view is the container of the big button, even if i touch on a small button within the scrollviews.
I've spend two days already for that and no result.What can cause this behaviour ?
EDIT : After krumelur's comment I've changed my focus from configuration of those views to animation i give to the container views, and i've noticed that, the problem is about the animation, i'm adding the the code part that animates all ten windows and behaves like a custom scrollview. All windows have their custom layer class and when i catch pangesture recognizer i move windows on the screen with following code. items in that code is an array which holds layers of all the windows. The animation causes that strange situation but i couldnt figure out yet..
- (void)layoutSublayers {
[super layoutSublayers];
[CATransaction begin];
[CATransaction setDisableActions:YES];
float angleDelta = 2 * M_PI / [items count];
float a = angle;
for (UIBaseLayer *l in items) {
l.position = self.position;
CATransform3D translation = CATransform3DMakeTranslation(cosf(a)*(radius.x), 1.0, (sinf(a)*radius.y) - radius.y*1.0);
float dailyAngle = (M_PI_2 - a);
CATransform3D rotation = CATransform3DMakeRotation(dailyAngle, 0, 1.0, 0);
CATransform3D t = CATransform3DConcat(rotation, translation);
l.transform = t;
a += angleDelta;
}
[CATransaction commit];}
http://img836.imageshack.us/img836/296/screenshot20111215at013.png
bringSubviewToFront did not work reliably on 5.0 (on 5.1 the hack was not needed)
I had to add a bigger transparrent UIButton around the button that behaved as if it was disabled to fix this on iOS prior to 5.1.
At last I've figured out that, even I send back views with CATransform3DMakeTranslation and layer.zPosition settings, touch events goes to views according to their frame position. The views that aren't currently even seen (overlayed by others) still catch touches. Writing just one line of code ([self.superview bringSubviewToFront:self]) for the view that is currently on screen solved the problem.
For testing this and understanding what I'm talking about, I've made simple test application that has only two buttons on it.
The blue and yellow buttons.The blue button overlays the yellow button so you can only see the blue one at the beginning.
On the touch up inside code for the blue button, I just send it back with buttons.layer.zPosition = -1. After this, there is no visible part of the blue button remains on screen, instead I see just the yellow button now, but when I touch the yellow button (or I think I am touching it) still blue buttons touch up inside code runs.
I'm not sure if this is the desired logic but it does not seem reasonable to me.
As I mentioned above, writing [blueButton.superview sendSubviewToBack:blueButton] while setting its layers zPosition to -1 works as expected.