开发者

How to create image and labels using location data stored in NSArray

开发者 https://www.devze.com 2023-01-31 00:24 出处:网络
i开发者_开发百科 have to create an 2images and 3 labels by using code (cgrectmake)and i am having X location, y location, width and height all are stored in arrays(which i have retrieved from the web

i开发者_开发百科 have to create an 2images and 3 labels by using code (cgrectmake)and i am having X location, y location, width and height all are stored in arrays(which i have retrieved from the web services)how can i create the image and labels can any one help me


You can join the elements of an array together with the NSString componentsJoinedByString class method:

NSString myString = [myNSArray componentsJoinedByString:@"x"];

where x is the characters you'd like to appear between each array element.


Edited to add

So in your newly-added code if these are the label values:

lbl = @"zero"
lbl1 = @"one"
lbl2 = @"two"

and you want to join them together with a space character then if you did this:

NSString *temp = [labelArray componentsJoinedByString:@" "];
NSLog(@"temp = %@", temp);

then this is what would be logged:

zero one two


Edited to further add

If you are instead trying to join the label values together to make xml elements then you might do something like this:

NSString *joinedElements = [labelArray componentsJoinedByString:@"</label><label>"];
NSString *temp = [NSString stringWithFormat:@"<label>%@</label>", joinedElements];
NSLog(@"temp = %@", temp);

then this is what would be logged:

<label>zero</label><label>one</label><label>two</label>


may be this is usefull to you.

NSString *str;

str = [arrayName objectAtIndex:i(Index NO)];

OK by this easily you can access object from the array. any type of object u can fetch this way only reception object type are change in left side.

Best of Luck.


Most objects have a -description method which returns a string representation of the object:

- (NSString *)description;

For example:

NSArray *array = [NSArray arrayWithObjects:@"The", @"quick", @"brown", @"fox", nil];
NSLog(@"%@", array); // prints the contents of the array out to the console.
NSString *arrayDescription = [array description]; // a string

It would help to know what you want to do with the string (how will you use the string). Also, what kind of objects do you have in the array?

In that case, Matthew's answer is one possibility. Another might be to use an NSMutableString and append the individual items, if you need control over how the string is created:

NSMutableString *string = [NSMutableString string];
if ([array count] >= 3) {
    [string appendString:[array objectAtIndex:0]];
    [string appendFormat:@"blah some filler text %@", [array objectAtIndex:1]];
    [string appendString:[array objectAtIndex:2]];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号