Crear una etiqueta en IBAction

I want to make it so when a button is clicked this a label comes up and will eventually animate. I made a start but this label does not show up at all. The CGRect coords are correct I am using a 3 page wide scroll view. Anyway, here is the code

UILabel *plusSymbol = [[UILabel alloc]initWithFrame:(CGRectMake(987, 349, 330, 326))];
plusSymbol.text = [NSString stringWithFormat:@"+%f", applesPerClick];

preguntado el 22 de septiembre de 13 a las 18:09

did you add the label as a subview? -

I assume not, how would I do this? -

2 Respuestas

try adding the label to the button.

UIButton *btn;
UILabel *label;

[btn addSubview:label];

Respondido el 22 de Septiembre de 13 a las 18:09

More likely to the buttons superview, but the principle is the same. - Wain

well, you are right but when you will add any object, it should ideally be placed on top if we go by the order of addition. - Shahil

When you create a view or button or anything from code you have to add to the screen:

UILabel *plusSymbol = [[UILabel alloc]initWithFrame:(CGRectMake(987, 349, 330, 326))];
plusSymbol.text = [NSString stringWithFormat:@"+%f", applesPerClick];
[self.view addSubview:plusSymbol];




//[yourParentView addSubview:plusSymbol];

If you want to add on the Button

[yourButton addSubview:plusSymbol];

But be careful because the frame is in your parentView. if your button is 100*100 then you have to modify the plusSymbol.frame. plusSymbol.frame = CGRectMake(0, 0, 100, 100);

Respondido el 22 de Septiembre de 13 a las 18:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.