Delay of highlight in UIButton in UIView - ios

Alright so normally this problem happens in a tableView's scrollView or scrollView of some sort but I am having a "halfway delay" on a UIButton that is contained in simply a UIView. Here's my code:
UIButton *brightnessUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[brightnessUpButton setFrame:CGRectMake(260, 0, 60, 144)]; //y:5 height:80
brightnessUpButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 0);
UIButton *brightnessDownButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 24, 40, 40)];
[brightnessUpButton setImage:[UIImage imageNamed:#"brightnessUp.png"] forState:UIControlStateNormal];
[brightnessUpButton setImage:[UIImage imageNamed:#"brightnessUpHighlighted.png"] forState:UIControlStateHighlighted];
[brightnessDownButton setImage:[UIImage imageNamed:#"brightnessDown.png"] forState:UIControlStateNormal];
[luxView addSubview:brightnessUpButton];
[luxView addSubview:brightnessDownButton];
So the problem is currently with brightnessUpButton. As you can see I did nothing but set the frame and content Insets. So the problem is when you click on the button. If you click below where the image appears in the button you get a 1-2 second delay for the highlight of the button. If you click on the image, you get an immediate highlight, and when you click above the image of the UIButton you get an immediate highlight.
This behavior makes no sense to me because the UIButton is added to a UIView, not a scrollView of any sort and the highlighting only happens immediately with half of the button. I have tried:
1) setting the imageEdgeInsets and contentEdgeInsets as apprropriate
2) Using the View debugger to see if there's some additional object interfering with the button - of which the result was NONE, the UIView exists on top of the UIView and that is all.
What could possibly be causing this weird behavior?

Related

How do I place a button at the end of the text in a UITextView?

I can't really think of a way on how to put a custom UIButton at the end of the text of the UITextView. Not its trailing ending, not its frame, but its text.
If only I could use UILabel, then I could just implement this functionality using TTTAttributedLabel.
My goal is just like that, not just a simple hide/show READ MORE functionality or whatsoever.
Here's the goal:
And here's a simple code, I'm using frame for now for some experiments instead of constraints - and besides, I can't see the use of constraints if I don't even know where to constraint the button.
UIImage *toggleDescriptionFieldButtonImage = self.isFieldDescriptionShown ?
[UIImage imageNamed:#"ic_field_desc_shown"] : [UIImage imageNamed:#"ic_field_desc_hidden"];
toggleDesciptionFieldButton = [UIButton buttonWithType:UIButtonTypeCustom];
toggleDesciptionFieldButton.frame = CGRectMake(0, 0, 25, 25);
[toggleDesciptionFieldButton setImage:toggleDescriptionFieldButtonImage forState:UIControlStateNormal];
[toggleDesciptionFieldButton addTarget:self
action:#selector(toggleDescriptionFieldPressed:)
forControlEvents:UIControlEventTouchUpInside];

UITableView Add FooterView Button Sometimes Tap Doesn't Perform Action

I have a simple UITableView that I've added a UIButton to the Footer.
Similar to this:
self.btn =[UIButton buttonWithType:UIButtonTypeCustom];
self.btn.backgroundColor = darkPurple;
[self.btn setTitle:#"Submit" forState:UIControlStateNormal];
[self.btn addTarget:self action:#selector(btnTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.btn.frame=CGRectMake(0, 0, self.tableView.frame.size.width, 100);
self.btn.showsTouchWhenHighlighted = true;
self.tableView.tableFooterView = self.btn;
Sometimes when I get scrolled to the bottom of the TableView if it isn't completely settled the Button won't perform the action. Sometimes it will flash (showsTouchWhenHighlighted) but I'll need to tap it again.
What am I missing here? I've tried solutions like this but it doesn't appear to work.
UIButton touch is delayed when in UIScrollView
I want to it process always, even if the scroll isn't settled and not delay.
What am I missing here?
Nothing. That's just how touches work on iOS. You can see the same thing in Mobile Safari: if the page is still scrolling, tapping a link doesn't work. You have to wait until the page is completely stopped ("settled", as you rightly say).

UIButton losing target after rotation

I have(/had) a UITextField subclass which has a custom delete button as a rightView property.
This is working fine up until I rotate the device and then the button does not react anymore.
I changed my approach and 'cheated' a bit. Now I'm adding the UIButton on top of the UITextField in code. Which also works fine up until I rotate the device. I checked with backgroundColors if there are no other elements on top of the button.
I also tried removing the button and adding it again when the device rotates. It's visible but the action does not trigger. If I start my app in Portrait or in Landscape it works up until I rotate the device.
How I add the button:
if (!btn_delete)
{
btn_delete = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 70, (tf_search.frame.size.height / 2) - 8, 17, 16)];
[btn_delete setImage:[UIImage imageNamed:#"icon_cross_textfield"] forState:UIControlStateNormal];
[btn_delete addTarget:self action:#selector(clearTextField:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn_delete];
[self.view bringSubviewToFront:btn_delete];
}
else
{
[btn_delete removeFromSuperview];
btn_delete = nil;
}
Method -(void)clearTextField:(UIButton*)sender does not get called after rotation.
Any advice is appreciated.
The UIButton was added to a UIViewController's UIView which was part of a UIView of another UIViewController. They all had clearColour as backgroundColor so the UIButton was still visible but not in the bounds of the superView.

Center custom TitleView containing an UIImage and UILabel

I checked all the other answers, but I cannot get it to work using what they say:
I have a UIView myTitle, with Frame (0,0,320,44) which contains an UIImage and a UILabel. The UIImage and the UILabel are fine and look fine, but I cannot seem to figure out how to center myTitle.
self.navigationItem.titleView = myTitle;
It shows up and looks ok, but much too far to the left. It seems to (logically) be related to the left bar button (the back button) which is auto generated by the framework when I push a controller. That barbutton has a varying width based on that and it changes the x of myTitle view based on that.
So, where can I get the width of the left (and right) barbuttons so I can figure out how to put myTitle that in the center?
I notice when I change the width of myTitle it (logically) will center (because the UIImage and UILabel are centered within myTitle).
To have more control, instead of having the left bar button auto -generated, set it using code as below.
UIButton *leftButton =[UIButton buttonWithType:UIButtonTypeCustom];
[leftButton setFrame:CGRectMake(0, 0, 100, 44)];
[leftButton setTitle:#"back" forState:UIControlStateNormal];
[leftButton setBackgroundColor:[UIColor greenColor]];
[leftButton addTarget:self action:#selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:leftButton];
Now you can perfectly adjust the frame of titleView with out much problem.
I found two ways in which it works;
Like Cy-4AH suggested, using autolayout; her/his answer would be the answer
Not using autolayout it was much simpler than I thought; if i make the titleView Width to fit it's content exactly, it automatically works; is that done with auto layout internally?
Hope this helps someone.

UIView/UIButton coordinates flipped

I have a coreplot project. The class of the view in viewcontroller has been changed to CPTGraphHostingView.
After creating the graph (this works fine),
I am adding a button as a subview , this launches a popover
the button shown is inverted. I have the same control in different view controllers and it works fine. The Popover also appears fine.
Here is the code that creates and adds the UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(monthSelection)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Change Month" forState:UIControlStateNormal];
button.frame = CGRectMake(330, 650, 111, 40);
[self.view addSubview:button];
[here is a screenshot of whats happening. UIButton is suppose to show somewhere below the popover. What am i missing.
Do not add subviews to the graph hosting view. Instead, make other views siblings of the hosting view, i.e., add them as subviews of the same superview.

Resources