简体   繁体   中英

Custom UIView doesn't look as expected

I would like to create a custom UIView so I could use it among a few UIViewControllers.

I created a xib file that looks like this:

在此处输入图片说明

The Above image has UIView, and inside 3 UIButtons

  1. I created TopBar : UIView
  2. I set the view size to freeform and the status bar to no.
  3. I set the File's Owner class to TopBar
  4. I dragged the UIView (which includes the 3 UIButtons) and called it contentView
  5. I added in TabBar.m the method:

-(void)awakeFromNib {
    [[NSBundle mainBundle] loadNibNamed:@"TopBar" owner:self options:nil];
    [self addSubview: _contentView];
}

  1. I added to my UIViewController via storyboard the UIView and set its class to TopBar and its size to the UIView size in the xib

However, the result looks like this:

Why? What is wrong? (as you can see the buttons are extremely big and have spaces between them). I am supporting only Ios6 and above

在此处输入图片说明

The problem was that auto-layout was checked in the xib file of TabBar.

I deselected it and now it displayed it property

If anyone needs, this shows how to deselect it in xcode 4.6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM