I an using a stepper to control the font size of a text view, but there is no action being fired until I press the stepper twice. Why is this happening?
The following code is for the `mystepper' IBAction:
- (IBAction) changeFontSize:(id)sender
{
[myStepper setMinimumValue:14.0]
self.myStepper.maximumValue =20.0;
CGFloat newSize = [myTextView fontWithSize:self.stepper.value];
self.myTextView.font = newSize;
}
Check whether u had connected the UIStepper Recieved Actions to the changeFontSize: function for Values Changed not for Touches inside
Is it possible to create two button shown as below image? It may seem like you should use UIButton or UIImageView but if i click to area 1, it stills acts as clicked to button 1. Button 2 should be fired when I click to the area 1 as well!
Failing the above responses being acceptable, you could implement a custom subclass of UIButton that overrides pointInside:withEvent:.
Assuming your view is exactly square and the graphic exactly circular and filling the entire square, an example might be:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// check that the point is at least inside the normal rect
if(![super pointInside:point withEvent:event]) return NO;
// we'll assume a square view with an exact circle inside, so
// the radius of the circle is just half the width
CGFloat radius = self.bounds.size.width*0.5f;
// the point (radius, radius) is also the centre of the view, so...
CGFloat squareOfDistanceFromCentre =
(radius - point.x)*(radius - point.x) +
(radius - point.y)*(radius - point.y);
// if the point is too far away, return NO
if(squareOfDistanceFromCentre > radius*radius) return NO;
// otherwise we've exhausted possible reasons for answering NO
return YES;
}
You can make circular button by cutting the layer and set radius of you button.
[[button layer] setCornerRadius:8.0f];
you can also try with change radius.
Yes, of course is possible.
You can connect a single action with more than one selector through IB.
You can also call directly the method fired by button2 from inside the method fired by button1.
It quite tricky, but possible:
You can use only one button, but put some verification after event touchUpInside. You should calculate if this touch point are inside the circle of "button1". For this task you need to have some mathematic knowledge - How do I calculate a point on a circle’s circumference?
Set userInteractionEnabled to NO for the smaller Button 1. All events will go to the larger Button 2.
I have created two round rect buttons for this purpose, one of them is long and thin, and the other one is more wide. Together they build a shape like a chubby plus sign, which is pretty close to a circle, considering apple accepts 44 px as the minimum confortably pressable size. If you want the image to change, set another image to its imageView for highlighted state and connect several actions (touchup wont be sufficient if you want to immitate buttons highlighted state on the image view)of the two buttons. Alternatively you can add observers and alter highlighted state of the imageview according to the buttons
A clean way to deal with pointInside on a circular button is this:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (![super pointInside:point withEvent:event])
{
return NO;
}
BOOL isInside = (pow((point.x-self.frame.size.width/2), 2) + pow((point.y - self.frame.size.height/2), 2) < pow((self.frame.size.width/2), 2)) ? YES:NO;
return isInside;
}
You can ditch the 'isInside' variabe, but this way is easier to test.
i have IBOutlet uislider. i want it to show the value of slider when the user presses the slider and change the value of it when the user take his hand off the slider i want it to disapper. So when the user touches to change the value of slider the label shows the value and when the user take his finger of the slider the label automaticly disapper.
My code is:
-(IBAction)sliderSlide:(UISlider *)aSlider {
float f=slider.value;
NSString *show=[NSString stringWithFormat:#"%.2f %%",f];
label2.text=show;
}
i know i need to use slider.highlited=YES; but where and how can i turn it back to hidden?
- (IBAction)touchEndedAction
{
self.label2.hidden = YES;
}
set the IBAction to the sliders UIControlEventEditingDidEnd or UIControlEventTouchCancel
try it out.
UIControlEventEditingDidEnd didn't work for me, but UIControlEventTouchDown works
Basically I have created a UISwipeGestureRecognizer for my UITableView for when the user swipes from left to right. When the user swipes right to left, the DELETE renders and functions as it should.
I'm trying to get a new custom UIButton to render exactly the same way the DELETE button renders when swiped. It doesn't slide in but sort of slowly reveals itself from right to left?
I would like to do this for my custom UIButton to appear in the same place as DELETE except this time only when the user swipes right to left.
I have this method set as the #selector after a swipe has been detected right to left:
- (void)displayAddArchiveView:(UIGestureRecognizer *)gestureRecognizer {
// Assume this is the view container that will contain my UIButton
GreenGradientView *archiveView = [[GreenGradientView alloc] initWithFrame:CGRectMake(211.0, 3.0, 63.0, 30.0)];
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
CGPoint swipeLocation = [gestureRecognizer locationInView:self.reportsTableView];
NSIndexPath *swipedIndexPath = [self.reportsTableView indexPathForRowAtPoint:swipeLocation];
ReportsTableViewCell *swipedCell = (ReportsTableViewCell *)[self.reportsTableView cellForRowAtIndexPath:swipedIndexPath];
[self tableView:reportsTableView willBeginEditingRowAtIndexPath:swipedIndexPath];
// HERE I should do some sort of UIView animation block to slowly reveal it
// from the right to left or something? Any suggestions. Not sure how to go about it?
[swipedCell addSubview:archiveView];
}
}
I have indicated by comments inside the code block my thoughts. The custom UIView actually does show up after swiping so I know it works. It's just a matter of getting the animation right, identical to how the DELETE button reveals itself? Suggestions?
Thanks!
You could try something like this
CGRect finalFrame = archiveView.frame;
archiveView.frame = CGRectMake(finalFrame.origin.x + finalFrame.size.width, finalFrame.origin.y, 0, finalFrame.size.height);
[UIView animateWithDuration:0.3 animations:^{
archiveView.frame = finalFrame;
}];
Basically I've reset the frame so it has no width and set the origin on the far right (so that it grows from the right towards the left). Then in the animation block, i set the frame to what I want it to be at the end. In your case you can just save the final frame in a local variable before you reset the frame to have zero width.
I have a TableView with custom TableCellViews that has UILabels and UIButtons on it.
when one of the buttons is taped I want to show a "tooltip" describing the text of the button.
Most everything is working except for when I try to convert the center coordinates of the UIButton to the coordinates of the rootView which is a UIView.
Here is the code:
- (void) fancyLabelButtonPressed: (UIButton *) button {
CGPoint btnPoint = button.center; // x=200.5 y=27.5
CGPoint rootViewPoint = [button convertPoint:btnPoint toView:rootView];
// rootViewPoint -> x=390.5 y=197.5
CGPoint pointToUse = CGPointMake(btnPoint.x +20, rootViewPoint.y - 23); // Hack to get it close
}
How can rootViewPoint.x=390.5 when I'm in portrait view?!!? By using the x from the button and the y from the rootViewPoint I get close to what it should be but it is just a hack.
Does anyone see what I'm doing wrong? or is there a better way?
This is because you are converting the point from the wrong view. The center property is actually in the coordinate system of the button's superview, whatever that is, so when you convert it to your rootView, you must convert it from there. So:
rootViewPoint = [[button superview] convertPoint:btnPoint toView:rootView];
That should give you what you are looking for.