iphone - Using xib object inside another xib -


i'm designing using ib specific button (with labels,and imageview , other stuff).

i use xib object (the button) in xib, have 6 objects of button.

i know can programmatically using class identifier, have position lables , image view, , set default values , else in code.

i'm wondering if it's possible same thing using ib ? (of course still set values in code, want positions of lables/imageview , rest set in xib)

thanks

edit

so, understand asked @ first not possible. i'm trying :

i created buttontest.xib. inside xib have uiview , 3 subviews (2 lables , button). in inspector set uiview class buttontest. inside buttontest.m have 3 outlets each of subviews, connect in ib.

next have buttontestviewcontroller.xib. inside put 1 view , set it's class in inspector buttontest. connect view mytextview outlet inside buttontestviewcontroller.m of class buttontest

now, code inside buttontestviewcontroller.m viewdidload:

- (void)viewdidload {     [super viewdidload];      nsarray *subviewarray = [[nsbundle mainbundle] loadnibnamed:@"buttontest" owner:nil options:nil];     buttontest *mainview = (buttontest*)[subviewarray objectatindex:0];      self.mytextview = mainview; } 

what hoped happen, view in buttontestviewcontroller.xib become view designed in buttontest.xib. isn't happening. happens view inside buttontestviewcontroller.xib stays same.

worth mentioning, if add:

[self.view addsubview:mainview]; 

it add new view, besides existing one.

any idea how want ?

eventually have 6 views in buttontestviewcontroller.xib, buttontest.xib template, , lables values set in code.

edit2

ok, guys did said , worked charm. problem have right issue when view in buttontestviewcontroller.xib little bigger view in buttontest.xib. when happens, lable on button extremely blurry. when both same size, it's good.

@ ned - used exact code posted in initwithcoder method, except switched frame sentence :

self.bounds = mainview.frame; 

i tried playing content mode in ib trying fix it, no avail.

when use posted, meaning :

mainview.frame = self.bounds; 

it's not working @ all, , both views' sizes stay same. here tried playing resizemask still didn't work.

and idea how fix these 2 issues ? guys!

edit 3

i did manage fix 1 of issues, resizing buttontestviewcontroller.xib buttontest.xib view size. did (using code solve blurry issue, taken here)

self.bounds = cgrectmake(0, 0, mainview.frame.size.width, mainview.frame.size.height);         cgrect overlay2frame = self.frame;         overlay2frame.origin.x = round(overlay2frame.origin.x);         overlay2frame.origin.y = round(overlay2frame.origin.y);         self.frame = overlay2frame; 

the other issue still can't solve. view in buttontest.xib won't bigger match other view.

you can this, , pretty easily. way create uiview subclass (let's it's called "myview.m" , "myview.h"), , nib called "myview.xib".

first, in nib, click file's owner, , set class "myview". make iboutlets/actions class show in ib. add single top-level view (if doesn't have 1 already) main view, , add other custom elements (uilabels , uiimageviews) subviews of main uiview.

next, add following code gets called when myview initialized (remember, if initialize nib you'll inited - (id)initwithcoder:(nscoder *)adecoder).

nsarray *subviewarray = [[nsbundle mainbundle] loadnibnamed:nsstringfromclass([self class]) owner:self options:nil]; uiview *mainview = [subviewarray objectatindex:0];  //just in case size different (you may or may not want this) mainview.frame = self.bounds;  [self addsubview:mainview]; 

what loads view hierarchy nib nsarray, , since had 1 top-level uiview, add subview of custom uiview.

this allows design uiviews (and other subclasses of uiview) in interface builder.

edit: updated op's edit.

the way i've done first following directions above. 1 difference in buttontest nib you're changing class of uiview buttontest, change file owner's class buttontest. then, inside buttontest.m, loadnibnamed stuff. now, add object buttontestviewcontroller.xib, add uiview (or uibutton, whatever buttontest subclassed from) , change class buttontest.

this little confusing, i'll try break file.

buttontestviewcontroller.xib: add uibutton (of whatever buttontest inherits from) , change class buttontest

buttontest.m: inside "initwithcoder" method, of "loadnibnamed" stuff have above

buttontest.xib: change file's owner class buttontest , link iboutlets , ibactions


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -