S
S
SiDChik2014-05-29 06:00:50
iOS
SiDChik, 2014-05-29 06:00:50

How to position UIButton relative to UITextField?

There is a separate class for UITextField. It is necessary that when creating a button was added to the right of it. That is, not inside the input itself, but at a short distance from it.
Currently I am trying to do the following:

- (void) awakeFromNib
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 50);
    [button setImage:[UIImage imageNamed:@"nice.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(focused:) forControlEvents:UIControlEventTouchUpInside];
    
    self.rightView = button;
    self.rightViewMode = UITextFieldViewModeAlways;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SiDChik, 2014-05-29
@SiDChik

This is the solution I came up with:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

CGFloat xPos =self.frame.size.width + self.frame.origin.x + 10;
CGFloat yPos =self.frame.origin.y;
button.frame = CGRectMake(xPos, yPos, self.frame.size.height, self.frame.size.height);
    
[button setImage:[UIImage imageNamed:@"nice.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(focused:) forControlEvents:UIControlEventTouchUpInside];
    
[self.superview addSubview:button];

S
Sergei Borisov, 2014-05-29
@risik

IMHO UIView, in which the UITextField and UIButton you need are created

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question