Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert NSArray of strings into UILabel and count by 1.
    primarykey
    data
    text
    <p>How Would I insert an array of strings into <code>UILabel</code>, and have them load or count by 1? I'm trying to load the following array into the <code>UILabel</code>: </p> <pre><code>self.array = [NSArray arrayWithObjects:@"Testing 1",@"Testing 2",@"Testing 3", nil]; </code></pre> <p>Here I am using an UIScrollView that automatically changes from each slide to each slide:</p> <pre><code> for (int i=1; i&lt;=3; i++) { // create label UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,30)]; text.text = [NSString stringWithFormat:@"%@", self.array]; text.font=[UIFont fontWithName:@"HelveticaNeueLTStd-LtCn" size:15]; text.textColor = [UIColor darkGrayColor]; text.textAlignment =NSTextAlignmentCenter; // create imageView UIImageView *lblView = [[UIImageView alloc] initWithFrame:CGRectMake((i-1)*scrMain.frame.size.width, 325, 280, 240)]; // set label [lblView addSubview:text]; // apply tag to access in future lblView.tag=i+1; // add to scrollView [scrMain addSubview:lblView]; } </code></pre> <p>I have an example of how to do it with <code>UIImageView</code>:</p> <pre><code>for (int i=1; i&lt;=3; i++) { // create image UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"sti%02i.png",i]]; // create imageView UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake((i-1)*scrMain.frame.size.width + 23, 60, 280, 260)]; // set scale to fill imgV.contentMode=UIViewContentModeScaleToFill; // set image [imgV setImage:image]; // apply tag to access in future imgV.tag=i+1; // add to scrollView [scrMain addSubview:imgV]; } </code></pre> <p>The images are in my project and are numbered sti01, sti02, and so on... It then counts by one for each images and then loads them into the scrollview. I hope this helps! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload