ios - Object properties to UILabel -


i have object 18 properties (number of properties in object static , not change on time). each property stores information. need create uilabels in cycle (for, foreach, etc.) , set current object.property current label. how can that?

you may use code that:

id object; // object nsarray *properties = @[ @"prop1", @"prop2", ... ]; // properties [properties enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) {     uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, idx * 30, 0, 30)]; // or set custom frame     label.text = [nsstring stringwithformat:@"%@", [object valueforkey:obj]];     [label sizetofit];     [self.view addsubview:label]; // add superview }]; 

you can of properties using objective-c runtime without having prepopulated properties array, please refer here so

notice if of properties scalar types code crash. need type check here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -