how to create a UIlabel using a string value in iPhone?
I have a situation where i have an strings in a NSMutableArray.i want to create UILabel/UITextField or any UI controls by using the string in that array.
For example the array is like this
NSMutableArray *myarray=[NSMutableArray initWithObjects:@"label1",@"label2",@"label3",nil];
now i will retrieve the object at index position 0 or 1 or 2.Then,i want to use that retrieved string/object to create a UILabel开发者_StackOverflow中文版 or anything, like this,
UILabel *theobjectretrievedfromthearray=[[UILabel alloc]init];
theobjectretrievedfromthearray means objects that are taken from the myarray
How can i do this?Please help me know for implementing this..
Thanks for everyone in advance.
ooooooooopsss it seems i didn't understand your question:
why don't you use tags for that ? i am guessing that you want to get to those labels later, so just use tags.
by the way if you don't accept answers, and feedback the users for their efforts you are not going to get answers. if you didn't know that it's time to learn.
good day shani
Do you want the strings to be the text on the labels? This is not so hard:
UILabel *theobjectretrievedfromarray = [[UILabel alloc] initWithFrame: CGRectMake(x, y, width, height)];
theobjectretrievedfromarry.text = [myarray objectAtIndex: i];
and that's about it. Easy Breasy
Use ObjectatIndex
:
UILabel *requiredobj=[arrayName objectAtIndex:0];
requiredobj=[UILabel alloc]initWithFrame:CGReckMake(0,0,13,50)];
.. .. do not forget to release the labels.
精彩评论